Version: Unity 6.5 (6000.5)
  • Supported
  • Legacy
Language : English
Debug generated C++ code
AppCallbacks class reference

WinRT API in C# scripts for UWP

Unity includes Windows Runtime (WinRT) support when building for Universal Windows Platform with the IL2CPP A Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary
scripting backend. Use Windows Runtime support to call into both native system Windows Runtime APIs as well as custom .winmd files directly from managed (C#) scriptsA piece of code that allows you to create your own Components, trigger game events, modify Component properties over time and respond to user input in any way you like. More info
See in Glossary
and plugins.

Unity automatically references Windows Runtime APIs such as Windows.winmd on Universal Windows Platform. To use custom .winmd files, import them into your Unity project folder together with any accompanying DLLs and configure them. For more information, refer to Import and configure plug-ins.

To use WinRT API in your Unity scripts:

  • Your scripts must be written in C#.
  • All the code that uses WinRT API must be under the ENABLE_WINMD_SUPPORT directive. This is necessary because the Editor uses Mono A scripting backend used in Unity. More info
    See in Glossary
    , which doesn’t support WinRT APIs.

The following code example gets an advertising ID 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
 }
}

Additional resources

Debug generated C++ code
AppCallbacks class reference
Copyright ©2005-2026 Unity Technologies. All rights reserved. Built from job ID 71047759. Built on: 2026年07月03日.

AltStyle によって変換されたページ (->オリジナル) /