Search Unity

Any Decent Instructions On UWP in Unity?

Discussion in 'Windows' started by LW, May 6, 2020.

  1. LW

    LW

    Joined:
    Jun 23, 2013
    Posts:
    22
    I can't seem to get any DLLs to work (it's always the Windows.Foundation.UniversalApiContract).

    Not found any clear instructions from MS or Unity on how to access things like Windows.Gaming or use an DLLs I've written.

    None of the forum posts have worked- my guess is, they are outdated because the instructions don't align with Unity's newer options.

    Any direction is appreciated!

    Thanks,

    (Also, sad that making tags is prohibited. Perhaps this is why no one can get easy answers when searching...)
     
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    Hey,

    To help you out we need more information:

    What exactly are you trying to do or which API do you want to use? Windows.Gaming is just a namespace (not a DLL) that contains several sets of APIs (.Input, .UI, .XboxLiveStorage., etc.).

    What exactly is the problem you're encountering? Is the problem when building your project/app or running it, i.e. compile errors or a runtime exception? Is the problem in Unity Editor or Visual Studio?

    When you say "DLLs I've written", what exactly are they: managed or native? Are you including them in your Unity project (Plugins) or trying referencing them directly from Visual Studio?

    This UWP page covers how to use WinRT APIs (i.e. Windows.Gaming.something) within your scripts: https://docs.unity3d.com/Manual/windowsstore-scripts.html

    This section of the manual covers adding Plugins (DLLs) to your Unity project:
    https://docs.unity3d.com/Manual/Plugins.html

    If the documentation is wrong or missing important details, please provide that feedback via the "Report a problem on this page".
     
  3. LW

    LW

    Joined:
    Jun 23, 2013
    Posts:
    22
    Thanks for the help @timke

    I'm trying to access Input from Windows.Gaming, specifically because I cannot locate the HID Output Report syntax for a racing wheel to control feedback (https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/HID.html).

    I tried bringing in a managed dll using Windows.Gaming.Input and I encountered that error I mentioned above:
    `Windows.Foundation.UniversalApiContract is missing.`

    I'm wondering if this is even testable in the editor....
     
  4. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    408
    Ah..HID *sigh*

    So, let me get this out of the way: using HID on UWP is a nightmare; the WinRT APIs around HID are awful and practically worthless. Microsoft seemed to go out of its way to hide the HID Report data making it very difficult to find the bit/byte offset for a given control.

    So, in your case using the WinRT RacingWheel API might be the best option, since even if you do find the Output Report control offsets for your racing wheel, they probably won't match those on a different device.

    BTW, a set of Input System layouts for various force-feedback devices would be a nice addition to the Asset Store.

    You can invoke WinRT API directly from scripts, however since they won't compile in the Editor you have to enclose them with #ifdef. The WinRT APIs will work when you build/run the actual UWP app.

    So for example:
    Code (CSharp):
    1.  
    2. #if ENABLE_WINMD_SUPPORT
    3. var racingWheel = Windows.Gaming.Input.RacingWheel.RacingWheels.FirstOrDefault();
    4. if (racingWheel != null)
    5. {
    6.     if (racingWheel.WheelMotor != null)
    7.     {
    8.         var axes = racingWheel.WheelMotor.SupportedAxes;
    9.  
    10.         if (Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X == (axes & Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X))
    11.         {
    12.         // Force can be applied through the X axis
    13.         }
    14.     }
    15. }
    16. #endif
    17.  
    I recommend writing a basic UWP "test app" in Visual Studio to implement the RacingWheel APIs and then port the code into Unity (easier to test this way).