/******************************************************************************* 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 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(); public XRDisplaySubsystem displaySubsystem { get { return GetLoadedSubsystem(); } } public XRInputSubsystem inputSubsystem { get { return GetLoadedSubsystem(); } } public override bool Initialize() { #if UNITY_INPUT_SYSTEM InputLayoutLoader.RegisterInputLayouts(); #endif #if UNITY_2020_1_OR_NEWER PXR_PTApi.UPxr_PTSetSRPState(GraphicsSettings.currentRenderPipeline != null); #else PXR_PTApi.System.UPxr_PTSetSRPState(false); #endif CreateSubsystem(displaySubsystemDescriptors, "PICO LP Display"); CreateSubsystem(inputSubsystemDescriptors, "PICO LP Input"); 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."); } return displaySubsystem != null; } public override bool Start() { StartSubsystem(); StartSubsystem(); Application.targetFrameRate = 72; return true; } public override bool Stop() { StopSubsystem(); StopSubsystem(); return true; } public override bool Deinitialize() { DestroySubsystem(); DestroySubsystem(); return true; } #if UNITY_EDITOR public string GetPreInitLibraryName(BuildTarget buildTarget, BuildTargetGroup buildTargetGroup) { return "PxrLivePreview"; } #endif } }