/// <summary> /// Initializes the device module. /// </summary> public static void InitializeDeviceModule(bool isFirst = true) { if (isInitialized) { return; } if (Application.platform == RuntimePlatform.Android) { Ximmerse.InputSystem.XDevicePlugin.Init(); //Apply logs: XDevicePlugin.SetLogger((int level, string _tag, string log) => { Debug.LogFormat("level:{0} ,tag:{1}, log:{2}", level, _tag, log); }); if (isFirst) { XDevicePlugin.CopyAssetsToPath(kConfigFileDirectory); } DevicerHandle.SlideInContext = XDevicePlugin.NewContext(XDevicePlugin.XContextTypes.kXContextTypeSlideIn);/// 创建SlideIn设备上下文 DevicerHandle.HmdHandle = XDevicePlugin.GetDeviceHandle(DevicerHandle.SlideInContext, "XHawk-0"); if (isFirst) { TagTrackingUtil.ApplyDefaultConfig(); } DeviceConnectionState vpuConn = (DeviceConnectionState)XDevicePlugin.GetInt(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, 0); isVPUConnected = vpuConn == DeviceConnectionState.Connected; XDevicePlugin.RegisterObserver(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, new XDevicePlugin.XDeviceConnectStateChangeDelegate(OnVPUConnectionStateChanged), DevicerHandle.HmdHandle); isInitialized = true; Debug.LogFormat("Slide in HLAPI initialized successfully. HLAPI version : {0}, Algorithm version: {1}", HLAPIVersion.Version, HLAPIVersion.AlgVersion); Debug.LogFormat("VPU device state {0} ", vpuConn); } else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { Ximmerse.InputSystem.XDevicePlugin.Init(); XDevicePlugin.SetLogger((int level, string _tag, string log) => { Debug.LogFormat("level:{0} ,tag:{1}, log:{2}", level, _tag, log); }); DevicerHandle.SlideInContext = XDevicePlugin.NewContext(XDevicePlugin.XContextTypes.kXContextTypeSlideIn);/// 创建SlideIn设备上下文 DevicerHandle.HmdHandle = XDevicePlugin.GetDeviceHandle(DevicerHandle.SlideInContext, "XHawk-0"); Debug.LogFormat("VPU Context: {0}, Hmd handle:{1}", DevicerHandle.SlideInContext.mNativeHandle.ToInt32(), DevicerHandle.HmdHandle.mNativeHandle.ToInt32()); TagTrackingUtil.ApplyDefaultConfig(); var vpuConn = (DeviceConnectionState)XDevicePlugin.GetInt(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, 0); isVPUConnected = vpuConn == DeviceConnectionState.Connected; XDevicePlugin.RegisterObserver(DevicerHandle.HmdHandle, XDevicePlugin.XVpuAttributes.kXVpuAttr_Int_ConnectionState, new XDevicePlugin.XDeviceConnectStateChangeDelegate(OnVPUConnectionStateChanged), DevicerHandle.HmdHandle); isInitialized = true; Debug.LogFormat("Slide in HLAPI initialized successfully. HLAPI version : {0}, Algorithm version: {1}", HLAPIVersion.Version, HLAPIVersion.AlgVersion); Debug.LogFormat("VPU device state {0} ", vpuConn); } else { Debug.LogWarningFormat("Tracking Library not available for current platform : {0}. Currently we supports Android/Windows platform.", Application.platform); } }
/// <summary> /// De-initialize the module. /// </summary> public static void DeInitializeModule() { if (isInitialized) { isInitialized = false; XDevicePlugin.ReleaseContext(DevicerHandle.HmdHandle); XDevicePlugin.SetLogger(null); XDevicePlugin.Exit(); } }