Handling Mouse Mode in Universal Apps (WSA/UWP)

Hi there!

I’m building a Windows Store version of our game, but have some problems with the Pointer/Mouse mode control from Unity. For Xbox, the pointer is obviously not ment to even be there, so I use this code to do so (based on this article):

public App()
{
    this.InitializeComponent();

    if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
        this.RequiresPointerMode = Windows.UI.Xaml.ApplicationRequiresPointerMode.WhenRequested;

    SetupOrientation();
    appCallbacks = new AppCallbacks();
}

However, I have to enter it manually to the App.xaml.cs file every time I make a new Unity build, which is a pain.

  1. Is there a way to handle this from within Unity?
  2. Can I also show and hide the cursor/pointer from within Unity whenever I need it? There are certain scenarios where virtual mouse makes more sense than gamepad controls.

Thanks a lot for any help!

Hey,

have you considered using this API - Unity - Scripting API: Cursor

Also, you can use WinRT API from within your scripts:

void Start ()
{
        AppCallbacks.Instance.InvokeOnUIThread(new AppCallbackItem(() =>
        {
if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Xbox")
       this.RequiresPointerMode = Windows.UI.Xaml.ApplicationRequiresPointerMode.WhenRequested;
}, false);

}

You could also try using D3D app type - which doesn’t have XAML so doesn’t automatically show the cursor.