Unity includes Windows Runtime support for IL2CPP on Windows Store and Xbox One platforms. Use Windows Runtime support to call into both native system Windows Runtime APIs as well as custom .winmd files directly from managed code (scripts and DLLs).
自動的に IL2CPP の Windows ランタイムサポートを有効にするには、PlayerSettings に移動し (Edit > Project Settings > Player)、 Configuration セクションで Api Compatibility Level を .NET 4.6 に設定します。
Unity automatically references Windows Runtime APIs (such as Windows.winmd on Windows Store) when it has Windows Runtime support enabled. To use custom .winmd files, import them (together with any accompanying DLLs) into your Unity project folder. Then use the Plugin Inspector to configure the files for your target platform.
In your Unity project’s scripts you can use the ENABLE_WINMD_SUPPORT
#define directive to check that your project has Windows Runtime support enabled. Use this before a call to .winmd Windows APIs or custom .winmd scripts to ensure they can run and to ensure any scripts not relevant to Windows ignore them. See the examples below.
例
C#
void Start() {
#if ENABLE_WINMD_SUPPORT
Debug.Log("Windows Runtime Support enabled");
// カスタムの .winmd API をここで呼び出します
#endif
}
JS
function Awake() {
#if ENABLE_WINMD_SUPPORT
Debug.Log("Windows Runtime Support enabled");
// Put calls to your custom .winmd API here
#endif
}
Windows ランタイムサポートが IL2CPP で有効な場合に定義されるのに加え、 Compilation Overrides を Use Net Core に設定する場合も .NET で定義されます。