Files
2025-07-21 09:11:14 +02:00

60 lines
2.3 KiB
C#

namespace Oculus.Platform
{
using UnityEngine;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public sealed class StandalonePlatform
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void UnityLogDelegate(IntPtr tag, IntPtr msg);
public Request<Models.PlatformInitialize> InitializeInEditor()
{
#if UNITY_ANDROID
if (String.IsNullOrEmpty(PlatformSettings.MobileAppID))
{
throw new UnityException("Update your App ID by selecting 'Oculus Platform' -> 'Edit Settings'");
}
var appID = PlatformSettings.MobileAppID;
#else
if (String.IsNullOrEmpty(PlatformSettings.AppID))
{
throw new UnityException("Update your App ID by selecting 'Oculus Platform' -> 'Edit Settings'");
}
var appID = PlatformSettings.AppID;
#endif
if (String.IsNullOrEmpty(StandalonePlatformSettings.OculusPlatformTestUserAccessToken))
{
throw new UnityException(
"Update your standalone credentials by selecting 'Oculus Platform' -> 'Edit Settings'");
}
var accessToken = StandalonePlatformSettings.OculusPlatformTestUserAccessToken;
return AsyncInitialize(UInt64.Parse(appID), accessToken);
}
public Request<Models.PlatformInitialize> AsyncInitialize(ulong appID, string accessToken)
{
CAPI.ovr_UnityResetTestPlatform();
CAPI.ovr_UnityInitGlobals(IntPtr.Zero);
return new Request<Models.PlatformInitialize>(
CAPI.ovr_PlatformInitializeWithAccessToken(appID, accessToken));
}
public Request<Models.PlatformInitialize> AsyncInitializeWithAccessTokenAndOptions(string appId,
string accessToken, Dictionary<InitConfigOptions, bool> initConfigOptions)
{
var configCount = (UIntPtr)initConfigOptions.Count;
var configPairs = CAPI.DictionaryToOVRKeyValuePairs(initConfigOptions);
return new Request<Models.PlatformInitialize>(
CAPI.ovr_PlatformInitializeWithAccessTokenAndOptions(UInt64.Parse(appId), accessToken, configPairs,
configCount));
}
}
}