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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UWP device detection

Discussion in 'Windows' started by Burve, May 6, 2016.

  1. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    I know, that with
    Code (CSharp):
    1. #if UNITY_WSA_10_0
    I can execute specific code if this is UWP build, however my question is - how can I check what device it is, mainly XBOX, build running on PC or on Mobile ?

    While it is nice that same build can work everywhere PC build require Exit button and mobile build require touch controls and not Xbox controller and it would be nice if my game can actually detect on what it is and work accordingly.

    Thanks.
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    (tl;dr Skip to the bottom to for detecting tablet vs desktop.)

    Well here's the reason it's hard. Microsoft is trying to remove the concept that mobile, desktop, and console are different things.

    Microsoft does not feel UWP apps need an exit button. Users should not need to worry about the lifecycle of the app. The OS provides ways to close an app already.

    Microsoft wants touch controls on both mobile, and desktop for those with touch screens. I wouldn't be surprised if touchscreens are common with Xboxs in the future .

    Xbox controllers can be attached to xboxs, desktops, and mobile platforms. Controllers should not be disabled only for mobile.

    This is Microsoft's style and what they would like in the future. I'm not saying MS is always right! f you still want to know if it is a touch interface or a mouse interface you can check:
    https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.viewmanagement.uiviewsettings.aspx

    I'm not sure how to check Xbox. Microsoft prefers we check for features instead of platforms. You can check what APIs are available for the current system.
    https://blogs.windows.com/buildinga...tecting-features-with-api-contracts-10-by-10/
     
  3. matt33315

    matt33315

    Joined:
    Mar 28, 2014
    Posts:
    94
    I would agree with this.

    In my game I am detecting if the user has a controller connected. If so I am showing / hiding certain UI elements.

    I have also gone through my game and ensured that the navigation properties on buttons are set correctly.

    I have opted for explicated navigation so I can control which objects get focus when the user navigates using a controller.
     
  4. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    Thanks, I got basic idea:

    * if controller detected use game pad
    * if controller is not detected assume it is touch screen
    ** if it is touch screen and keyboard key is pressed switch to PC
    ** if in PC and tap/mouse click is detected switch to touch screen

    Thanks for help.