Windows ランタイムサポートを有効にしている場合は、Unity スクリプトで直接 WinRT API を使用できます。WinRT API の使用方法と Windows ランタイムサポートを有効にする方法については、Windows ランタイムサポート を参照してください。
Unity スクリプトで WinRT API を使用するには、以下の要件を満たす必要があります。
ENABLE_WINMD_SUPPORT ディレクティブの下に配置する必要があります。これは、エディターが WinRT API をサポートしない Mono を使用するため必要です。このコード例は、直接 WinRT API を使用して広告を取得する方法を示しています。
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
}
}