Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Windows Store App: How to detect if on mobile?

Discussion in 'Windows' started by tbg10101_, Jan 16, 2016.

  1. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    Hello,

    I would like to be able to detect if my Windows Store app is running on a mobile device?

    This is because I want to hide the exit button in the menu on mobile devices but show it on desktop devices.

    I have tried RuntimePlatform but the only options for WSA are WSAPlayerX86, WSAPlayerX64, and WSAPlayerARM. This doesn't work when there are ARM laptops and x68/x64 phones/tablets.

    Does anybody else have a reliable method?

    Thanks,
    -Tristan
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
    Is there a reason why you want to show exit button on desktop? There's already close button on every window:

    upload_2016-1-16_13-39-26.png

    What you want to detect is pretty hard... and even depends on the mode a device is in. For example, what happens when you connect a monitor to a phone and it gets a desktop and windowed windows?
     
  3. Indie Viking

    Indie Viking

    Joined:
    Sep 12, 2013
    Posts:
    28
    Sevenate likes this.
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
    To add on this: it's a really bad idea to use it to change your application functionality. You never know what kind of new device families are going to be added in the future.
     
    angrypenguin likes this.
  5. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    When the application is in full-screen, that button is not visible and I'd rather not force my users exit fullscreen to be able to exit the game using a mouse.

    However, this does give me another idea. I think I will only show the button if a mouse is present. That should work.
     
    Last edited: Jan 16, 2016
    angrypenguin likes this.
  6. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    In case anyone is interested, this solution seems to be working:
    Code (CSharp):
    1.         //show exit button if there is a mouse
    2.         if (Input.mousePresent) {
    3.             exitButton.gameObject.SetActive(true);
    4.         }
    5.  
    6.         //override exit button visibility for certain platforms
    7. #if UNITY_STANDALONE
    8.         exitButton.gameObject.SetActive(true);
    9. #elif UNITY_WEBPLAYER || UNITY_WEBGL
    10.         exitButton.gameObject.SetActive(false);
    11. #endif
     
  7. Indie Viking

    Indie Viking

    Joined:
    Sep 12, 2013
    Posts:
    28
    I don't now if this is a problem, but what happens when your game is running on a Surface Pro 4 using pen or touch?

    Another idea is to detect if device has hardware (or software emulated) back button present, and only hide the exit button when device back button is present.

    Code (CSharp):
    1. if (ApiInformation.IsApiContractPresent("Windows.Phone.PhoneContract",1,0))
    2. {
    3.   //device has hardware or software emulated back button
    4. }
     
    angrypenguin likes this.
  8. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    This is excellent!
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,478
    Well, if a phone is hooked up to a monitor and uses mouse + keyboard, your check will still return true. I'd think you'd want to give it a desktop experience in that case.
     
    Sevenate and angrypenguin like this.
  10. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    Indeed, after some testing I went back to my original solution.
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
    Microsoft guideline used to advise against close button in the app.

    That being said, checking for PhoneContract like @Indie Viking suggested is the right way.
     
  12. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,624
    On a second thought, it looks more of an issue to adapt UI to certain screen size, rather than device type.
    Screen.width and Screen.height and decide, which size allows you enough space to show the button + check for mouse presence, as touch requires much bigger button than mouse.
     
  13. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    This is what I use

    Code (CSharp):
    1. public static bool IsWindowsStorePhone()
    2.     {
    3. #if UNITY_WP_8_1
    4.         return true;
    5. #else
    6.         return false;
    7. #endif
    8.     }
     
  14. seccia

    seccia

    Joined:
    Nov 11, 2015
    Posts:
    4
    use SystemInfo.supportsVibration
     
  15. tbg10101_

    tbg10101_

    Joined:
    Mar 13, 2011
    Posts:
    191
    What if I plug a controller into my PC?

    What if I am using a Windows 10 phone?
     
  16. seccia

    seccia

    Joined:
    Nov 11, 2015
    Posts:
    4
    SystemInfo.deviceType==DeviceType.Desktop
    It works with 5.4.0b13
     
  17. Aseemy

    Aseemy

    Joined:
    Aug 22, 2015
    Posts:
    203
    i would like the give the user option to change resolution in the desktop app but not in the mobile app. how would i do that in universal 10 app?
    SystemInfo.deviceType==DeviceType.Desktop, is this the best way to do it?
     
  18. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    This is the code I use for checking windows store build for desktop and mobile.

    Code (CSharp):
    1.  
    2.     public static bool IsWindowsStoreDesktop()
    3.     {
    4. #if UNITY_WSA
    5.         return IsWindowsStorePhone() == false;
    6. #else
    7.         return false;
    8. #endif
    9.        
    10.     }
    11.  
    12.     public static bool IsWindowsStorePhone()
    13.     {
    14. #if UNITY_WP_8_1
    15.         return true;
    16. #else
    17.         return false;
    18. #endif
    19.     }