So here is the situation:
Surface tablets do support touch and keyboard / mouse.
A laptop running windows 8 without touchscreen does not support touch, but keyboard and mouse.
If you build a windows 8 game, it will be available on both surface and laptop.
So, my question; how can one detcct if current device (laptop or surface) has got touchscreen?
(I kn ow application.platform, but that doesn’t covers something like ‘metrodesktop’ or ‘metrosurface’.)
I think you can implement both keyboard mouse input or touch screen accelerator input. Then no matter the current device got touch screen or not, the application can get correct input.
Sample code:
(1) For keyboard and accelerator:
if (Input.GetKey(KeyCode.LeftArrow)) {
//Do something while press left arrow
}
else if (Input.GetKey(KeyCode.RightArrow)) {
//Do something while press right arrow
}
else {
// Get the input of accelerator
InputX = Input.acceleration.x;
}
}
(2) For touch screen and mouse:
Work in the same way with following events:
public override void OnTouchBegan(UITouch touch) {
…
}
public override void OnTouchMoved(UITouch touch) {
…
}
public override void OnTouchEnded(UITouch touch) {
…
}
P.S. First time to reply and answer question, hope it can help you.
Kenma is correct in that you don’t want different code for tablets and laptops… you want to be able to support both touch and keyboard/mouse regardless of platform, and simply respond to the appropriate events. (Also, some laptops also support touch screens.)
Thnx for the replys!
It is not really an issue of having code for both mouse and touch, but more that a desktop version should look more like a game that that can be played without touch. E.g. smaller buttons or disable some touch stuff at all. For instance, in my game, I have splitscreen modus, that only makes sense on a tablet and not on a desktop, so I want to disable that at all and give the gamer on desktop not that choice.
I was not able to make it work! Any advice anybody?
What I need more is to detect if the mouse available now or not… When I change the Ultrabook to Tablet Mode, Unity hide the hardware mouse and lock the mouse position, but I’m using a custom mouse (a gameobject) and I was not able to detected this change.
I tested it with TouchScreenKeyboard-isSupported.html but on my Ultrabook it always returns me true! I’m still not able to detect when the user is using it on Tablet or Notebook Mode.
Hey @sevensails , did you continue work on this? Is it still working, even if you can’t publish on the Windows Store? I’m investigating the topic and would love a way to detect the convertible state.