Any Decent Instructions On UWP in Unity?

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…)

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: Unity - Manual: WinRT API in C# scripts for UWP

This section of the manual covers adding Plugins (DLLs) to your Unity project:

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

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…

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:

#if ENABLE_WINMD_SUPPORT
var racingWheel = Windows.Gaming.Input.RacingWheel.RacingWheels.FirstOrDefault();
if (racingWheel != null)
{
    if (racingWheel.WheelMotor != null)
    {
        var axes = racingWheel.WheelMotor.SupportedAxes;

        if (Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X == (axes & Windows.Gaming.Input.ForceFeedback.ForceFeedbackEffectAxes.X))
        {
        // Force can be applied through the X axis
        }
    }
}
#endif

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).