/******************************************************************************* Copyright © 2015-2022 PICO Technology Co., Ltd.All rights reserved. NOTICE:All information contained herein is, and remains the property of PICO Technology Co., Ltd. The intellectual and technical concepts contained herein are proprietary to PICO Technology Co., Ltd. and may be covered by patents, patents in process, and are protected by trade secret or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden unless prior written permission is obtained from PICO Technology Co., Ltd. *******************************************************************************/ #if (UNITY_ANDROID && !UNITY_EDITOR) #define PICO_PLATFORM #endif using System; using System.Collections.Generic; using System.Runtime.InteropServices; #if PICO_XR using Unity.XR.PXR; #else using Unity.XR.OpenXR.Features.PICOSupport; #endif using UnityEngine; using UnityEngine.XR; namespace Unity.XR.PICO.TOBSupport { public partial class PXR_EnterprisePlugin { private const string TAG = "[PXR_EnterprisePlugin]"; public const int MAX_SIZE = 12208032; public static string token; private static int curSize = 0; private static bool camOpenned = false; private static FrameItemExt antiDistortionFrameItemExt; private static FrameItemExt distortionFrameItemExt; private static bool initDistortionFrame; [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int getHeadTrackingConfidence(); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int openVSTCamera(); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int closeVSTCamera(); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int getHeadTrackingData(Int64 predictTime, ref SixDof data, int type); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int acquireVSTCameraFrame(ref FrameItemExt frame); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int acquireVSTCameraFrameAntiDistortion(string token, Int32 width, Int32 height, ref FrameItemExt frame); [DllImport("libpxr_xrsdk_native", CallingConvention = CallingConvention.Cdecl)] public static extern int getCameraParameters(string token, out RGBCameraParams rgb_Camera_Params); #if PICO_XR [DllImport("pxr_api", CallingConvention = CallingConvention.Cdecl)] #else [DllImport("openxr_pico", EntryPoint = "PICO_GetPredictedDisplayTime", CallingConvention = CallingConvention.Cdecl)] #endif public static extern int Pxr_GetPredictedDisplayTime(ref double predictedDisplayTime); #if PICO_XR [DllImport("pxr_api", CallingConvention = CallingConvention.Cdecl)] #else [DllImport("openxr_pico", EntryPoint = "PICO_GetPredictedMainSensorState2", CallingConvention = CallingConvention.Cdecl)] #endif public static extern int Pxr_GetPredictedMainSensorState2(double predictTimeMs, ref PxrSensorState2 sensorState, ref int sensorFrameIndex); #if PICO_PLATFORM private static AndroidJavaClass unityPlayer; private static AndroidJavaObject currentActivity; private static AndroidJavaObject tobHelper; private static AndroidJavaClass tobHelperClass; private static AndroidJavaObject IToBService; private static AndroidJavaClass BAuthLib; #endif public static Action BoolCallback; public static Action IntCallback; public static Action LongCallback; public static Action StringCallback; private static AndroidJavaObject GetEnumType(Enum enumType) { AndroidJavaClass enumjs = new AndroidJavaClass("com.pvr.tobservice.enums" + enumType.GetType().ToString().Replace("Unity.XR.PICO.TOBSupport.", ".PBS_")); AndroidJavaObject enumjo = enumjs.GetStatic(enumType.ToString()); return enumjo; } public static bool UPxr_InitEnterpriseService() { #if PICO_PLATFORM tobHelperClass = new AndroidJavaClass("com.picoxr.tobservice.ToBServiceUtils"); tobHelper = tobHelperClass.CallStatic("getInstance"); unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); currentActivity = unityPlayer.GetStatic("currentActivity"); BAuthLib = new AndroidJavaClass("com.pvr.tobauthlib.AuthCheckServer"); #endif return UPxr_GetToken(); } public static void UPxr_SetBindCallBack(BindCallback mBoolCallback) { #if PICO_PLATFORM tobHelper.Call("setBindCallBack", mBoolCallback); #endif } public static void UPxr_BindEnterpriseService(Action callback = null) { #if PICO_PLATFORM UPxr_SetBindCallBack(new BindCallback(callback)); tobHelper.Call("bindTobService", currentActivity); #endif } public static void UPxr_UnBindEnterpriseService() { #if PICO_PLATFORM tobHelper.Call("unBindTobService"); #endif } public static void GetServiceBinder() { #if PICO_PLATFORM IToBService = tobHelper.Call("getServiceBinder"); #endif } public static string UPxr_StateGetDeviceInfo(SystemInfoEnum type) { string result = ""; #if PICO_PLATFORM if (IToBService == null) { return result; } result = IToBService.Call("pbsStateGetDeviceInfo", GetEnumType(type), 0); #endif return result; } public static void UPxr_ControlSetDeviceAction(DeviceControlEnum deviceControl, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsControlSetDeviceAction", GetEnumType(deviceControl), new IntCallback(callback)); #endif } public static void UPxr_ControlAPPManager(PackageControlEnum packageControl, string path, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsControlAPPManger", GetEnumType(packageControl), path, 0, new IntCallback(callback)); #endif } public static void UPxr_ControlSetAutoConnectWIFI(string ssid, string pwd, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsControlSetAutoConnectWIFI", ssid, pwd, 0, new BoolCallback(callback)); #endif } public static void UPxr_ControlClearAutoConnectWIFI(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsControlClearAutoConnectWIFI", new BoolCallback(callback)); #endif } public static void UPxr_PropertySetHomeKey(HomeEventEnum eventEnum, HomeFunctionEnum function, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsPropertySetHomeKey", GetEnumType(eventEnum), GetEnumType(function), new BoolCallback(callback)); #endif } public static void UPxr_PropertySetHomeKeyAll(HomeEventEnum eventEnum, HomeFunctionEnum function, int timesetup, string pkg, string className, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsPropertySetHomeKeyAll", GetEnumType(eventEnum), GetEnumType(function), timesetup, pkg, className, new BoolCallback(callback)); #endif } public static void UPxr_PropertyDisablePowerKey(bool isSingleTap, bool enable, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsPropertyDisablePowerKey", isSingleTap, enable, new IntCallback(callback)); #endif } public static void UPxr_PropertySetScreenOffDelay(ScreenOffDelayTimeEnum timeEnum, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsPropertySetScreenOffDelay", GetEnumType(timeEnum), new IntCallback(callback)); #endif } public static void UPxr_PropertySetSleepDelay(SleepDelayTimeEnum timeEnum) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsPropertySetSleepDelay", GetEnumType(timeEnum)); #endif } public static void UPxr_SwitchSystemFunction(SystemFunctionSwitchEnum systemFunction, SwitchEnum switchEnum) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsSwitchSystemFunction", GetEnumType(systemFunction), GetEnumType(switchEnum), 0); #endif } public static void UPxr_SwitchSetUsbConfigurationOption(USBConfigModeEnum uSBConfigModeEnum) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsSwitchSetUsbConfigurationOption", GetEnumType(uSBConfigModeEnum), 0); #endif } public static void UPxr_SetControllerPairTime(ControllerPairTimeEnum timeEnum, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsSetControllerPairTime", GetEnumType(timeEnum),new IntCallback(callback), 0); #endif } public static void UPxr_GetControllerPairTime(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsGetControllerPairTime",new IntCallback(callback), 0); #endif } public static void UPxr_ScreenOn() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsScreenOn"); #endif } public static void UPxr_ScreenOff() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsScreenOff"); #endif } public static void UPxr_AcquireWakeLock() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsAcquireWakeLock"); #endif } public static void UPxr_ReleaseWakeLock() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsReleaseWakeLock"); #endif } public static void UPxr_EnableEnterKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsEnableEnterKey"); #endif } public static void UPxr_DisableEnterKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsDisableEnterKey"); #endif } public static void UPxr_EnableVolumeKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsEnableVolumeKey"); #endif } public static void UPxr_DisableVolumeKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsDisableVolumeKey"); #endif } public static void UPxr_EnableBackKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsEnableBackKey"); #endif } public static void UPxr_DisableBackKey() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsDisableBackKey"); #endif } public static void UPxr_ResetAllKeyToDefault(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsResetAllKeyToDefault", new BoolCallback(callback)); #endif } public static void UPxr_SetAPPAsHome(SwitchEnum switchEnum, string packageName) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsAppSetAPPAsHomeTwo", GetEnumType(switchEnum), packageName); #endif } public static void UPxr_KillAppsByPidOrPackageName(int[] pids, string[] packageNames) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsKillAppsByPidOrPackageName", pids, packageNames, 0); #endif } public static void UPxr_KillBackgroundAppsWithWhiteList(string[] packageNames) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsKillBackgroundAppsWithWhiteList",packageNames, 0); #endif } public static void UPxr_FreezeScreen(bool freeze) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsFreezeScreen", freeze); #endif } public static void UPxr_OpenMiracast() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsOpenMiracast"); #endif } public static bool UPxr_IsMiracastOn() { bool value = false; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsIsMiracastOn"); #endif return value; } public static void UPxr_CloseMiracast() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsCloseMiracast"); #endif } public static void UPxr_StartScan() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsStartScan"); #endif } public static void UPxr_StopScan() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsStopScan"); #endif } public static void UPxr_ConnectWifiDisplay(string modelJson) { #if PICO_PLATFORM tobHelper.Call("pbsConnectWifiDisplay", modelJson); #endif } public static void UPxr_DisConnectWifiDisplay() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsDisConnectWifiDisplay"); #endif } public static void UPxr_ForgetWifiDisplay(string address) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsForgetWifiDisplay", address); #endif } public static void UPxr_RenameWifiDisplay(string address, string newName) { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsRenameWifiDisplay", address, newName); #endif } public static void UPxr_SetWDModelsCallback(Action> callback) { #if PICO_PLATFORM tobHelper.Call("pbsSetWDModelsCallback", new WifiDisplayModelCallback(callback)); #endif } public static void UPxr_SetWDJsonCallback(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsSetWDJsonCallback", new StringCallback(callback)); #endif } public static void UPxr_UpdateWifiDisplays() { #if PICO_PLATFORM if (IToBService == null) { return; } IToBService.Call("pbsUpdateWifiDisplays"); #endif } public static string UPxr_GetConnectedWD() { string result = ""; #if PICO_PLATFORM result = tobHelper.Call("pbsGetConnectedWD"); #endif return result; } public static void UPxr_SwitchLargeSpaceScene(bool open, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsSwitchLargeSpaceScene", new BoolCallback(callback), open, 0); #endif } public static void UPxr_GetSwitchLargeSpaceStatus(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsGetSwitchLargeSpaceStatus",new StringCallback(callback), 0); #endif } public static bool UPxr_SaveLargeSpaceMaps() { bool value = false; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsSaveLargeSpaceMaps", 0); #endif return value; } public static void UPxr_ExportMaps(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsExportMaps", new BoolCallback(callback), 0); #endif } public static void UPxr_ImportMaps(Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsImportMaps", new BoolCallback(callback), 0); #endif } public static float[] UPxr_GetCpuUsages() { float[] data = null; #if PICO_PLATFORM data = tobHelper.Call("pbsGetCpuUsages"); #endif return data; } public static float[] UPxr_GetDeviceTemperatures(int type, int source) { float[] data = null; #if PICO_PLATFORM if (IToBService == null) { return null; } data = IToBService.Call("pbsGetDeviceTemperatures", type, source); #endif return data; } public static void UPxr_Capture() { #if PICO_PLATFORM IToBService.Call("pbsCapture"); #endif } public static void UPxr_Record() { #if PICO_PLATFORM IToBService.Call("pbsRecord"); #endif } public static void UPxr_ControlSetAutoConnectWIFIWithErrorCodeCallback(String ssid, String pwd, int ext, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsControlSetAutoConnectWIFIWithErrorCodeCallback",ssid,pwd,ext,new IntCallback(callback)); #endif } public static void UPxr_AppKeepAlive(String appPackageName, bool keepAlive, int ext) { #if PICO_PLATFORM if (IToBService == null) { return ; } IToBService.Call("pbsAppKeepAlive",appPackageName,keepAlive,ext); #endif } public static void UPxr_TimingStartup(int year, int month, int day, int hour, int minute, bool open) { #if PICO_PLATFORM if (IToBService == null) { return ; } IToBService.Call("pbsTimingStartup", year, month, day, hour, minute, open); #endif } public static void UPxr_TimingShutdown(int year, int month, int day, int hour, int minute, bool open) { #if PICO_PLATFORM if (IToBService == null) { return ; } IToBService.Call("pbsTimingShutdown", year, month, day, hour, minute, open); #endif } public static void UPxr_StartVrSettingsItem(StartVRSettingsEnum settingsEnum, bool hideOtherItem, int ext) { #if PICO_PLATFORM if (IToBService == null) { return ; } IToBService.Call("pbsStartVrSettingsItem", GetEnumType(settingsEnum), hideOtherItem, ext); #endif } public static void UPxr_SwitchVolumeToHomeAndEnter(SwitchEnum switchEnum, int ext) { #if PICO_PLATFORM if (IToBService == null) { return ; } IToBService.Call("pbsSwitchVolumeToHomeAndEnter", GetEnumType(switchEnum), ext); #endif } public static SwitchEnum UPxr_IsVolumeChangeToHomeAndEnter() { SwitchEnum switchEnum = SwitchEnum.S_OFF; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsIsVolumeChangeToHomeAndEnter"); if (num == 0) { switchEnum = SwitchEnum.S_ON; } else if (num == 1) { switchEnum = SwitchEnum.S_OFF; } #endif return switchEnum; } public static int UPxr_InstallOTAPackage(String otaPackagePath) { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsInstallOTAPackage",otaPackagePath, 0); #endif return value; } public static string UPxr_GetAutoConnectWiFiConfig() { string value= ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetAutoConnectWiFiConfig", 0); #endif return value; } public static string UPxr_GetTimingStartupStatus() { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetTimingStartupStatus", 0); #endif return value; } public static string UPxr_GetTimingShutdownStatus() { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetTimingShutdownStatus", 0); #endif return value; } public static int UPxr_GetControllerKeyState(ControllerKeyEnum pxrControllerKey) { int value = 1; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetControllerKeyState", GetEnumType(pxrControllerKey),0); #endif return value; } public static int UPxr_SetControllerKeyState(ControllerKeyEnum controllerKeyEnum, SwitchEnum status) { int value = 1; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsSetControllerKeyState", GetEnumType(controllerKeyEnum),GetEnumType(status),0); #endif return value; } public static SwitchEnum UPxr_ControlGetPowerOffWithUSBCable() { SwitchEnum switchEnum = SwitchEnum.S_OFF; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsControlGetPowerOffWithUSBCable",0); if (num == 0) { switchEnum = SwitchEnum.S_ON; } else if (num == 1) { switchEnum = SwitchEnum.S_OFF; } #endif return switchEnum; } public static ScreenOffDelayTimeEnum UPxr_PropertyGetScreenOffDelay() { ScreenOffDelayTimeEnum screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.NEVER; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsPropertyGetScreenOffDelay", 0); switch (num) { case 0: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.THREE; break; case 1: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.TEN; break; case 2: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.THIRTY; break; case 3: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.SIXTY; break; case 4: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.THREE_HUNDRED; break; case 5: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.SIX_HUNDRED; break; case 6: screenOffDelayTimeEnum = ScreenOffDelayTimeEnum.NEVER; break; } #endif return screenOffDelayTimeEnum; } public static SleepDelayTimeEnum UPxr_PropertyGetSleepDelay() { SleepDelayTimeEnum sleepDelayTime = SleepDelayTimeEnum.NEVER; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsPropertyGetSleepDelay", 0); switch (num) { case 0: sleepDelayTime = SleepDelayTimeEnum.FIFTEEN; break; case 1: sleepDelayTime = SleepDelayTimeEnum.THIRTY; break; case 2: sleepDelayTime = SleepDelayTimeEnum.SIXTY; break; case 3: sleepDelayTime = SleepDelayTimeEnum.THREE_HUNDRED; break; case 4: sleepDelayTime = SleepDelayTimeEnum.SIX_HUNDRED; break; case 5: sleepDelayTime = SleepDelayTimeEnum.ONE_THOUSAND_AND_EIGHT_HUNDRED; break; case 6: sleepDelayTime = SleepDelayTimeEnum.NEVER; break; } #endif return sleepDelayTime; } public static string UPxr_PropertyGetPowerKeyStatus() { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPropertyGetPowerKeyStatus", 0); #endif return value; } public static int UPxr_GetEnterKeyStatus() { int value = 1; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetEnterKeyStatus",0); #endif return value; } public static int UPxr_GetVolumeKeyStatus() { int value = 1; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetVolumeKeyStatus",0); #endif return value; } public static int UPxr_GetBackKeyStatus() { int value = 1; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetBackKeyStatus",0); #endif return value; } public static string UPxr_PropertyGetHomeKeyStatus(HomeEventEnum homeEvent) { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPropertyGetHomKeyStatus", GetEnumType(homeEvent),0); #endif return value; } public static void UPxr_GetSwitchSystemFunctionStatus(SystemFunctionSwitchEnum systemFunction, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsGetSwitchSystemFunctionStatus", GetEnumType(systemFunction), new IntCallback(callback), 0); #endif } public static string UPxr_SwitchGetUsbConfigurationOption() { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsSwitchGetUsbConfigurationOption", 0); #endif return value; } public static string UPxr_GetCurrentLauncher() { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetCurrentLauncher", 0); #endif return value; } public static int UPxr_PICOCastInit(Action callback) { int value = 0; #if PICO_PLATFORM value = tobHelper.Call("pbsPicoCastInit", new IntCallback(callback), 0); #endif return value; } public static int UPxr_PICOCastSetShowAuthorization(int authZ) { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPicoCastSetShowAuthorization",authZ,0); #endif return value; } public static int UPxr_PICOCastGetShowAuthorization() { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPicoCastGetShowAuthorization",0); #endif return value; } public static string UPxr_PICOCastGetUrl(PICOCastUrlTypeEnum urlType) { string value = ""; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPicoCastGetUrl",GetEnumType(urlType), 0); #endif return value; } public static int UPxr_PICOCastStopCast() { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPicoCastStopCast",0); #endif return value; } public static int UPxr_PICOCastSetOption(PICOCastOptionOrStatusEnum castOptionOrStatus, PICOCastOptionValueEnum castOptionValue) { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsPicoCastSetOption",GetEnumType(castOptionOrStatus),GetEnumType(castOptionValue),0); #endif return value; } public static PICOCastOptionValueEnum UPxr_PICOCastGetOptionOrStatus(PICOCastOptionOrStatusEnum castOptionOrStatus) { PICOCastOptionValueEnum value = PICOCastOptionValueEnum.STATUS_VALUE_ERROR; #if PICO_PLATFORM int num = 0; if (tobHelper == null) { return value; } num = tobHelper.Call("pbsPicoCastGetOptionOrStatus", GetEnumType(castOptionOrStatus), 0); switch (num) { case 0: value = PICOCastOptionValueEnum.OPTION_VALUE_RESOLUTION_HIGH; break; case 1: value = PICOCastOptionValueEnum.OPTION_VALUE_RESOLUTION_MIDDLE; break; case 2: value = PICOCastOptionValueEnum.OPTION_VALUE_RESOLUTION_AUTO; break; case 3: value = PICOCastOptionValueEnum.OPTION_VALUE_RESOLUTION_HIGH_2K; break; case 4: value = PICOCastOptionValueEnum.OPTION_VALUE_RESOLUTION_HIGH_4K; break; case 5: value = PICOCastOptionValueEnum.OPTION_VALUE_BITRATE_HIGH; break; case 6: value = PICOCastOptionValueEnum.OPTION_VALUE_BITRATE_MIDDLE; break; case 7: value = PICOCastOptionValueEnum.OPTION_VALUE_BITRATE_LOW; break; case 8: value = PICOCastOptionValueEnum.OPTION_VALUE_AUDIO_ON; break; case 9: value = PICOCastOptionValueEnum.OPTION_VALUE_AUDIO_OFF; break; case 10: value = PICOCastOptionValueEnum.STATUS_VALUE_STATE_STARTED; break; case 11: value = PICOCastOptionValueEnum.STATUS_VALUE_STATE_STOPPED; break; case 12: value = PICOCastOptionValueEnum.STATUS_VALUE_ERROR; break; } #endif return value; } public static int UPxr_SetSystemLanguage(String language) { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsSetSystemLanguage", language, 0); #endif return num; } public static String UPxr_GetSystemLanguage() { string value = ""; #if PICO_PLATFORM value = IToBService.Call("pbsGetSystemLanguage", 0); #endif return value; } public static int UPxr_ConfigWifi(String ssid, String pwd) { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsConfigWifi",ssid,pwd, 0); #endif return num; } public static String[] UPxr_GetConfiguredWifi() { #if PICO_PLATFORM return IToBService.Call("pbsGetConfiguredWifi",0); #endif return null; } public static int UPxr_SetSystemCountryCode(String countryCode, Action callback) { int num = 0; #if PICO_PLATFORM num = tobHelper.Call("pbsSetSystemCountryCode",countryCode,new IntCallback(callback),0); #endif return num; } public static string UPxr_GetSystemCountryCode() { string value = ""; #if PICO_PLATFORM value = IToBService.Call("pbsGetSystemCountryCode",0); #endif return value; } public static int UPxr_SetSkipInitSettingPage(int flag) { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsSetSkipInitSettingPage",flag,0); #endif return num; } public static int UPxr_GetSkipInitSettingPage() { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsGetSkipInitSettingPage",0); #endif return num; } public static int UPxr_IsInitSettingComplete() { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsIsInitSettingComplete",0); #endif return num; } public static int UPxr_StartActivity(String packageName, String className, String action, String extra, String[] categories, int[] flags) { int num = 0; #if PICO_PLATFORM num = IToBService.Call("pbsStartActivity", packageName, className, action, extra, categories, flags, 0); #endif return num; } public static int UPxr_CustomizeAppLibrary(String[] packageNames, SwitchEnum switchEnum) { int num = 0; #if PICO_PLATFORM if (IToBService == null) { return num; } num = IToBService.Call("pbsCustomizeAppLibrary", packageNames,GetEnumType(switchEnum), 0); #endif return num; } public static int[] UPxr_GetControllerBattery() { #if PICO_PLATFORM if (IToBService == null) { return null; } return IToBService.Call("pbsGetControllerBattery", 0); #endif return null; } public static int UPxr_GetControllerConnectState() { int num = 0; #if PICO_PLATFORM if (IToBService == null) { return num; } num = IToBService.Call("pbsGetControllerConnectState",0); #endif return num; } public static string UPxr_GetAppLibraryHideList() { string value = " "; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetAppLibraryHideList",0); #endif return value; } public static int UPxr_SetScreenCastAudioOutput(ScreencastAudioOutputEnum screencastAudioOutput) { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsSetScreenCastAudioOutput",GetEnumType(screencastAudioOutput),0); #endif return value; } public static ScreencastAudioOutputEnum UPxr_GetScreenCastAudioOutput() { ScreencastAudioOutputEnum value = ScreencastAudioOutputEnum.AUDIO_ERROR; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsGetScreenCastAudioOutput",0); switch (num) { case 0: value = ScreencastAudioOutputEnum.AUDIO_SINK; break; case 1: value = ScreencastAudioOutputEnum.AUDIO_TARGET; break; case 2: value = ScreencastAudioOutputEnum.AUDIO_SINK_TARGET; break; } #endif return value; } public static int UPxr_CustomizeSettingsTabStatus(CustomizeSettingsTabEnum customizeSettingsTabEnum, SwitchEnum switchEnum) { int value = 0; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsCustomizeSettingsTabStatus", GetEnumType(customizeSettingsTabEnum), GetEnumType(switchEnum), 0); #endif return value; } public static SwitchEnum UPxr_GetCustomizeSettingsTabStatus(CustomizeSettingsTabEnum customizeSettingsTabEnum) { SwitchEnum switchEnum = SwitchEnum.S_OFF; #if PICO_PLATFORM int num = 0; num = tobHelper.Call("pbsGetCustomizeSettingsTabStatus",GetEnumType(customizeSettingsTabEnum),0); if (num == 0) { switchEnum = SwitchEnum.S_ON; } else if (num == 1) { switchEnum = SwitchEnum.S_OFF; } #endif return switchEnum; } public static void UPxr_SetPowerOffWithUSBCable(SwitchEnum switchEnum) { #if PICO_PLATFORM if (IToBService==null) { return; } IToBService.Call("pbsControlSetPowerOffwithUSBCable", GetEnumType(switchEnum),0); #endif } public static void UPxr_RemoveControllerHomeKey(HomeEventEnum EventEnum) { #if PICO_PLATFORM if (IToBService==null) { return; } IToBService.Call("pbsRemoveControllerHomeKey", GetEnumType(EventEnum)); #endif } public static void UPxr_SetPowerOnOffLogo(PowerOnOffLogoEnum powerOnOffLogoEnum, String path, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsPropertySetPowerOnOffLogo",GetEnumType(powerOnOffLogoEnum),path,0, new BoolCallback(callback)); #endif } public static void UPxr_SetIPD(float ipd, Action callback) { #if PICO_PLATFORM tobHelper.Call("pbsSetIPD",ipd, new IntCallback(callback)); #endif } public static string UPxr_GetAutoMiracastConfig() { string value = " "; #if PICO_PLATFORM if (IToBService == null) { return value; } value = IToBService.Call("pbsGetAutoMiracastConfig",0); #endif return value; } public static int UPxr_SetPicoCastMediaFormat(PicoCastMediaFormat mediaFormat) { int value = -1; #if PICO_PLATFORM value = tobHelper.Call("setPicoCastMediaFormat",mediaFormat.bitrate,0); #endif return value; } public static int UPxr_setMarkerInfoCallback(TrackingOriginModeFlags trackingMode,float cameraYOffset,Action> mediaFormat) { int value = -1; #if PICO_PLATFORM value = tobHelper.Call("setMarkerInfoCallback",new MarkerInfoCallback(trackingMode,cameraYOffset,mediaFormat)); #endif return value; } private static bool UPxr_GetToken() { PLog.i(TAG, "GetToken Start"); #if PICO_PLATFORM token = BAuthLib.CallStatic("featureAuthByToken", currentActivity, "getCameraInfo"); #endif if (string.IsNullOrEmpty(token)) { PLog.e(TAG, "Failed to obtain token, camera data cannot be obtained!"); return false; } PLog.i(TAG, "GetToken End token :" + token); return true; } public static int UPxr_GetHeadTrackingConfidence() { PLog.d(TAG, "GetHeadTrackingConfidence Start"); int result = -1; #if PICO_PLATFORM result = getHeadTrackingConfidence(); #endif PLog.d(TAG, "GetToken End result :" + result); return result; } public static bool UPxr_OpenVSTCamera() { PLog.d(TAG, "OpenVSTCamera Start"); if (camOpenned) { PLog.d(TAG, "Camera has Openned!"); return true; } int result = -1; #if PICO_PLATFORM result = openVSTCamera(); #endif camOpenned = result == 0; PLog.d(TAG, "OpenVSTCamera End result :" + result + ", camOpenned : " + camOpenned); return result == 0; } public static bool UPxr_CloseVSTCamera() { PLog.d(TAG, "CloseVSTCamera Start"); if (!camOpenned) { PLog.d(TAG, "Camera has Closed!"); return true; } int result = -1; #if PICO_PLATFORM result = closeVSTCamera(); #endif camOpenned = !(result == 0); PLog.d(TAG, "CloseVSTCamera End result :" + result + ", camOpenned : " + camOpenned); return result == 0; } public static int UPxr_GetHeadTrackingData(Int64 predictTime, ref SixDof data, int type) { PLog.d(TAG, "GetHeadTrackingData Start"); int result = -1; #if PICO_PLATFORM result = getHeadTrackingData(predictTime, ref data, type); #endif PLog.d(TAG, "GetHeadTrackingData End result :" + result); return result; } public static int UPxr_AcquireVSTCameraFrame(out Frame frame) { PLog.d(TAG, "AcquireVSTCameraFrame Start"); frame = new Frame(); if (string.IsNullOrEmpty(token)) { PLog.e(TAG, "Failed to obtain token, camera data cannot be obtained!"); return -1; } if (!camOpenned) { PLog.e(TAG, "Failed to obtain data due to camera not being turned on!"); return -1; } InitDistortionFrame(); int result = -1; #if PICO_PLATFORM result = acquireVSTCameraFrame(ref distortionFrameItemExt); #endif frame.width = distortionFrameItemExt.frame.width; frame.height = distortionFrameItemExt.frame.height; frame.timestamp = distortionFrameItemExt.frame.timestamp; frame.datasize = distortionFrameItemExt.frame.datasize; frame.data = distortionFrameItemExt.frame.data; if (frame.pose != null) { frame.pose.position.x = (float)distortionFrameItemExt.six_dof_pose.pose.x; frame.pose.position.y = (float)distortionFrameItemExt.six_dof_pose.pose.y; frame.pose.position.z = (float)distortionFrameItemExt.six_dof_pose.pose.z; frame.pose.rotation.w = (float)distortionFrameItemExt.six_dof_pose.pose.rw; frame.pose.rotation.x = (float)distortionFrameItemExt.six_dof_pose.pose.rx; frame.pose.rotation.y = (float)distortionFrameItemExt.six_dof_pose.pose.ry; frame.pose.rotation.z = (float)distortionFrameItemExt.six_dof_pose.pose.rz; } frame.status = distortionFrameItemExt.six_dof_pose.pose.confidence; PLog.d(TAG, "AcquireVSTCameraFrame End result :" + result); return result; } public static int UPxr_AcquireVSTCameraFrameAntiDistortion(int width, int height, out Frame frame) { PLog.d(TAG, "AcquireVSTCameraFrameAntiDistortion Start width:" + width + ", height:" + height); frame = new Frame(); if (string.IsNullOrEmpty(token)) { PLog.e(TAG, "Failed to obtain token, camera data cannot be obtained!"); return -1; } if (!camOpenned) { PLog.e(TAG, "Failed to obtain data due to camera not being turned on!"); return -1; } int size = width * height * 3; InitAntiDistortionFrame(size); int result = -1; #if PICO_PLATFORM result = acquireVSTCameraFrameAntiDistortion(token, width, height, ref antiDistortionFrameItemExt); #endif PLog.d(TAG, "AcquireVSTCameraFrameAntiDistortion End result :" + result + ", width : " + antiDistortionFrameItemExt.frame.width + ", height : " + antiDistortionFrameItemExt.frame.height + ", datasize : " + antiDistortionFrameItemExt.frame.datasize + ", data : " + antiDistortionFrameItemExt.frame.data + ", confidence : " + antiDistortionFrameItemExt.six_dof_pose.pose.confidence); frame.width = antiDistortionFrameItemExt.frame.width; frame.height = antiDistortionFrameItemExt.frame.height; frame.timestamp = antiDistortionFrameItemExt.frame.timestamp; frame.datasize = antiDistortionFrameItemExt.frame.datasize; frame.data = antiDistortionFrameItemExt.frame.data; if (frame.pose != null) { frame.pose.position.x = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.x; frame.pose.position.y = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.y; frame.pose.position.z = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.z; frame.pose.rotation.w = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rw; frame.pose.rotation.x = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rx; frame.pose.rotation.y = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.ry; frame.pose.rotation.z = (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rz; } frame.status = antiDistortionFrameItemExt.six_dof_pose.relocation_pose.confidence; PLog.d(TAG, "zzzzzz relocation_pose.x=" + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.x + ", relocation_pose.y=" + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.y + ", relocation_pose.z=: " + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.z + ", relocation_pose.rw=: " + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rw + ", relocation_pose.rx = " + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rx + ", relocation_pose.ry = " + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.ry + ", relocation_pose.rz = " + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.rz); PLog.d(TAG, "zzzzzz pose.x=" + (float)antiDistortionFrameItemExt.six_dof_pose.relocation_pose.x + ", pose.y=" + (float)antiDistortionFrameItemExt.six_dof_pose.pose.y + ", relocation_pose.z=: " + (float)antiDistortionFrameItemExt.six_dof_pose.pose.z + ", pose.rw=: " + (float)antiDistortionFrameItemExt.six_dof_pose.pose.rw + ", pose.rx = " + (float)antiDistortionFrameItemExt.six_dof_pose.pose.rx + ", pose.ry = " + (float)antiDistortionFrameItemExt.six_dof_pose.pose.ry + ", pose.rz = " + (float)antiDistortionFrameItemExt.six_dof_pose.pose.rz); return result; } public static UnityEngine.Pose ToUnityPose(UnityEngine.Pose poseR) { UnityEngine.Pose poseL; poseL.position.x = poseR.position.x; poseL.position.y = poseR.position.y; poseL.position.z = -poseR.position.z; poseL.rotation.x = poseR.rotation.x; poseL.rotation.y = poseR.rotation.y; poseL.rotation.z = -poseR.rotation.z; poseL.rotation.w = -poseR.rotation.w; return poseL; } // RGB Camera pose (Left-handed coordinate system: X right, Y up, Z out) public static UnityEngine.Pose ToRGBCameraPose(RGBCameraParams cameraParams, UnityEngine.Pose headPose) { Vector3 headToCameraPos = new Vector3((float)cameraParams.x, (float)cameraParams.y, (float)cameraParams.z); Quaternion headToCameraRot = new Quaternion((float)cameraParams.rx, (float)cameraParams.ry, (float)cameraParams.rz, (float)cameraParams.rw); Matrix4x4 headMx = Matrix4x4.TRS(headPose.position, headPose.rotation, Vector3.one); Matrix4x4 cameraMx = Matrix4x4.TRS(headToCameraPos, headToCameraRot, Vector3.one); Matrix4x4 rgbMx = headMx * cameraMx; Matrix4x4 rotX180 = Matrix4x4.Rotate(Quaternion.Euler(180f, 0f, 0f)); rgbMx *= rotX180; #if UNITY_2021_2_OR_NEWER UnityEngine.Pose rgbCameraPose = ToUnityPose(new UnityEngine.Pose(rgbMx.GetPosition(), rgbMx.rotation)); #else UnityEngine.Pose rgbCameraPose = ToUnityPose(new UnityEngine.Pose(new Vector3(rgbMx.m03, rgbMx.m13, rgbMx.m23), rgbMx.rotation)); #endif return rgbCameraPose; } private static void InitDistortionFrame() { if (initDistortionFrame) { return; } distortionFrameItemExt = new FrameItemExt(); initDistortionFrame = true; } private static void InitAntiDistortionFrame(int size) { if (curSize == size) { return; } Debug.LogFormat("InitAntiDistortionFrame curSize={0}, size={1}", curSize, size); antiDistortionFrameItemExt = new FrameItemExt(); if (antiDistortionFrameItemExt.frame.data != IntPtr.Zero) { Marshal.FreeHGlobal(antiDistortionFrameItemExt.frame.data); antiDistortionFrameItemExt.frame.data = IntPtr.Zero; } antiDistortionFrameItemExt.frame.data = Marshal.AllocHGlobal(size); curSize = size; } public static RGBCameraParams UPxr_GetCameraParameters() { PLog.d(TAG, "GetCameraParameters Start"); RGBCameraParams rgbCameraParams = new RGBCameraParams(); if (string.IsNullOrEmpty(token)) { PLog.e(TAG, "Failed to obtain token, camera data cannot be obtained!"); return rgbCameraParams; } int result = getCameraParameters(token, out rgbCameraParams); PLog.d(TAG, "GetCameraParameters End result :" + result); return rgbCameraParams; } public static double UPxr_GetPredictedDisplayTime() { PLog.d(TAG, "UPxr_GetPredictedDisplayTime()"); double predictedDisplayTime = 0; #if PICO_PLATFORM Pxr_GetPredictedDisplayTime(ref predictedDisplayTime); #endif PLog.d(TAG, "UPxr_GetPredictedDisplayTime() predictedDisplayTime:" + predictedDisplayTime); return predictedDisplayTime; } public static SensorState UPxr_GetPredictedMainSensorState(double predictTime) { SensorState sensorState = new SensorState(); PxrSensorState2 sensorState2 = new PxrSensorState2(); int sensorFrameIndex = 0; #if PICO_PLATFORM Pxr_GetPredictedMainSensorState2(predictTime, ref sensorState2, ref sensorFrameIndex); #endif sensorState.status = sensorState2.status == 3 ? 1 : 0; sensorState.pose.position.x = sensorState2.pose.position.x; sensorState.pose.position.y = sensorState2.pose.position.y; sensorState.pose.position.z = sensorState2.pose.position.z; sensorState.pose.rotation.x = sensorState2.pose.orientation.x; sensorState.pose.rotation.y = sensorState2.pose.orientation.y; sensorState.pose.rotation.z = sensorState2.pose.orientation.z; sensorState.pose.rotation.w = sensorState2.pose.orientation.w; return sensorState; } public static int UPxr_gotoSeeThroughFloorSetting() { int value = -1; #if PICO_PLATFORM value = IToBService.Call("gotoSeeThroughFloorSetting",0); #endif return value; } public static int UPxr_fileCopy(String srcPath, String dstPath, FileCopyCallback callback) { int value = -1; #if PICO_PLATFORM value = tobHelper.Call("FileCopy",srcPath,dstPath,callback); #endif return value; } public static void UPxr_IsMapInEffect(String path, Action callback) { #if PICO_PLATFORM tobHelper.Call("isMapInEffect",path,new IntCallback(callback),0); #endif } public static void UPxr_ImportMapByPath(String path, Action callback) { #if PICO_PLATFORM tobHelper.Call("importMapByPath",path,new IntCallback(callback),0); #endif } private const string LibraryName = "PICO_TOBAPI"; [DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)] public static extern float oxr_get_trackingorigin_height(); } }