Universal Windows Platform Player Settings
Universal Windows Platform: WinRT API in C# scripts
It is possible to use WinRT API directly in Unity scripts. However there are limitations and requirements for this:
- Scripts must be written in C#, it’s not possible to use WinRT API from UnityScript
- Scripts must be compiled using Microsoft’s compiler, not Mono. This requires to set compilation overrides to Use .NET Core or Use .NET Core Partially, in the later case scripts must not be under Plugins or Standard Assets folders
- Because the same script code is also used by Unity Editor (which always uses Mono), all code that uses WinRT API must be under ENABLE_WINMD_SUPPORT define
Below is an example for getting advertising using WinRT API directly:
using UnityEngine;
public class WinRTAPI : MonoBehaviour {
void Update() {
auto adId = GetAdvertisingId();
// ...
}
string GetAdvertisingId() {
#if ENABLE_WINMD_SUPPORT
return Windows.System.UserProfile.AdvertisingManager.AdvertisingId;
#else
return "";
#endif
}
}
Note: when using IL2CPP scripting backend, this is only supported when using .NET 4.6 compatiblity profile.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Is something described here not working as you expect it to? It might be a Known Issue. Please check with the Issue Tracker at issuetracker.unity3d.com.
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
Universal Windows Platform Player Settings