/******************************************************************************* 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 hererin 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. *******************************************************************************/ using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; using UnityEngine.XR.Management; using UnityEngine.XR; #if UNITY_INPUT_SYSTEM using UnityEngine.InputSystem; using UnityEngine.InputSystem.Layouts; using UnityEngine.InputSystem.XR; using Unity.XR.PICO.LivePreview.Input; #endif #if UNITY_EDITOR using UnityEditor; #endif #if XR_HANDS using UnityEngine.XR.Hands; #endif namespace Unity.XR.PICO.LivePreview { #if UNITY_INPUT_SYSTEM #if UNITY_EDITOR [InitializeOnLoad] #endif static class InputLayoutLoader { static InputLayoutLoader() { RegisterInputLayouts(); } public static void RegisterInputLayouts() { InputSystem.RegisterLayout(matches: new InputDeviceMatcher().WithInterface(XRUtilities.InterfaceMatchAnyVersion).WithProduct(@"^(PICO Live Preview HMD)")); InputSystem.RegisterLayout(matches: new InputDeviceMatcher().WithInterface(XRUtilities.InterfaceMatchAnyVersion).WithProduct(@"^(PICO Live Preview Controller)")); } } #endif public class PXR_PTLoader : XRLoaderHelper #if UNITY_EDITOR , IXRLoaderPreInit #endif { private static List displaySubsystemDescriptors = new List(); private static List inputSubsystemDescriptors = new List(); #if XR_HANDS private static List handSubsystemDescriptors = new List(); #endif public XRDisplaySubsystem displaySubsystem { get { return GetLoadedSubsystem(); } } public XRInputSubsystem inputSubsystem { get { return GetLoadedSubsystem(); } } public override bool Initialize() { #if UNITY_INPUT_SYSTEM InputLayoutLoader.RegisterInputLayouts(); #endif PXR_PTApi.UPxr_PTSetSRPState(GraphicsSettings.currentRenderPipeline != null); CreateSubsystem(displaySubsystemDescriptors, "PICO LP Display"); CreateSubsystem(inputSubsystemDescriptors, "PICO LP Input"); #if XR_HANDS CreateSubsystem(handSubsystemDescriptors, "PICO LP Hands"); #endif if (displaySubsystem == null && inputSubsystem == null) { Debug.LogError("PXRLog Unable to start PICO Plugin."); } else if (displaySubsystem == null) { Debug.LogError("PXRLog Failed to load display subsystem."); } else if (inputSubsystem == null) { Debug.LogError("PXRLog Failed to load input subsystem."); } #if XR_HANDS var handSubSystem = GetLoadedSubsystem(); if (handSubSystem == null) { Debug.LogError("PXRLog Failed to load XRHandSubsystem."); } #endif return displaySubsystem != null; } public override bool Start() { PXR_PTApi.UPxr_PTSetSRPState(GraphicsSettings.currentRenderPipeline != null); StartSubsystem(); StartSubsystem(); #if XR_HANDS StartSubsystem(); #endif Application.targetFrameRate = 72; return true; } public override bool Stop() { StopSubsystem(); StopSubsystem(); #if XR_HANDS StopSubsystem(); #endif return true; } public override bool Deinitialize() { DestroySubsystem(); DestroySubsystem(); #if XR_HANDS DestroySubsystem(); #endif return true; } #if UNITY_EDITOR public string GetPreInitLibraryName(BuildTarget buildTarget, BuildTargetGroup buildTargetGroup) { return "PxrLivePreview"; } #endif } }