├── Scripts ├── .gitignore ├── variables.bat ├── clean_debug_env.bat ├── setup_debug_env.bat └── package_release.bat ├── SteamVRLib_Valve.VR ├── SteamVR │ ├── Input │ │ ├── SteamVR_DefaultAction.cs │ │ ├── SteamVR_DefaultActionSet.cs │ │ ├── SteamVR_Input_References.cs │ │ ├── Plugins │ │ │ └── JSON.NET │ │ │ │ └── Valve.Newtonsoft.Json.dll │ │ ├── SteamVR_Input_ActionScopes.cs │ │ ├── SteamVR_Input_ActionSetUsages.cs │ │ ├── BehaviourUnityEvents │ │ │ ├── SteamVR_Behaviour_SingleEvent.cs │ │ │ ├── SteamVR_Behaviour_BooleanEvent.cs │ │ │ ├── SteamVR_Behaviour_PoseEvent.cs │ │ │ ├── SteamVR_Behaviour_SkeletonEvent.cs │ │ │ ├── SteamVR_Behaviour_Vector2Event.cs │ │ │ ├── SteamVR_Behaviour_Vector3Event.cs │ │ │ ├── SteamVR_Behaviour_Pose_ConnectedChangedEvent.cs │ │ │ ├── SteamVR_Behaviour_Pose_DeviceIndexChangedEvent.cs │ │ │ ├── SteamVR_Behaviour_Pose_TrackingChangedEvent.cs │ │ │ ├── SteamVR_Behaviour_Skeleton_ConnectedChangedEvent.cs │ │ │ └── SteamVR_Behaviour_Skeleton_TrackingChangedEvent.cs │ │ ├── SteamVR_ActionDirections.cs │ │ ├── SteamVR_UpdateModes.cs │ │ ├── SteamVR_Action_Out.cs │ │ ├── SteamVR_Input_Generator_Names.cs │ │ ├── SteamVR_Input_Sources.cs │ │ ├── SteamVR_ActivateActionSetOnLoad.cs │ │ ├── SteamVR_Input_Source.cs │ │ ├── SteamVR_Behaviour_SkeletonCustom.cs │ │ ├── SteamVR_Skeleton_Pose.cs │ │ ├── SteamVR_ActionSet_Manager.cs │ │ ├── SteamVR_Behaviour_Vector3.cs │ │ ├── SteamVR_Behaviour_Single.cs │ │ └── SteamVR_Behaviour_Vector2.cs │ └── Scripts │ │ ├── SteamVR_CameraFlip.cs │ │ ├── SteamVR_CameraMask.cs │ │ ├── SteamVR_EnumEqualityComparer.cs │ │ ├── SteamVR_ExternalCamera_LegacyManager.cs │ │ ├── SteamVR_SphericalProjection.cs │ │ ├── SteamVR_Ears.cs │ │ ├── SteamVR_TrackingReferenceManager.cs │ │ ├── SteamVR_TrackedObject.cs │ │ ├── SteamVR_Skybox.cs │ │ ├── SteamVR_Fade.cs │ │ ├── SteamVR_Frustum.cs │ │ ├── SteamVR_RingBuffer.cs │ │ └── SteamVR_Overlay.cs ├── StreamingAssets │ └── SteamVR │ │ ├── binding_vive_tracker_camera.json │ │ ├── binding_index_hmd.json │ │ ├── binding_vive_cosmos.json │ │ ├── binding_rift.json │ │ ├── binding_vive.json │ │ ├── binding_vive_pro.json │ │ ├── binding_holographic_hmd.json │ │ └── actions.json ├── XR │ └── Settings │ │ └── OpenVRSettings.asset ├── SteamVR_Input │ ├── ActionSetClasses │ │ ├── SteamVR_Input_ActionSet_mixedreality.cs │ │ ├── SteamVR_Input_ActionSet_platformer.cs │ │ ├── SteamVR_Input_ActionSet_buggy.cs │ │ └── SteamVR_Input_ActionSet_default.cs │ ├── SteamVR_Input_Initialization.cs │ └── SteamVR_Input_ActionSets.cs └── SteamVRLib_Valve.VR.csproj ├── .gitignore ├── HC_VRTrial ├── AssetBundles │ ├── .gitignore │ ├── custom_asset_bundle │ └── UI-Unlit-Transparent.shader ├── VRUtils │ ├── UIScreenPanel.cs │ ├── CustomAssetManager.cs │ ├── IMGUICapture.cs │ ├── VR.cs │ ├── UGUICapture.cs │ ├── CameraHijacker.cs │ └── VRCamera.cs ├── Logging │ └── PluginLog.cs ├── Plugin.cs ├── HC_VRTrial.csproj ├── PluginConfig.cs └── SimpleVRController.cs ├── .gitattributes ├── SteamVRLib_Unity.XR.OpenVR ├── x64 │ ├── openvr_api.dll │ ├── ucrtbased.dll │ └── XRSDKOpenVR.dll ├── DeviceLayouts.cs ├── UnitySubsystemsManifest.json ├── SteamVRLib_Unity.XR.OpenVR.csproj ├── OpenVRHelpers.cs └── OpenVREvents.cs ├── SteamVRLib_UnityEngine.XR.Management ├── Subsystem │ ├── IntegratedSubsystemExtensions.cs │ ├── IntegratedSubsystemDescriptorExtensions.cs │ └── SubsystemManagerExtensions.cs ├── IXRLoaderPreInit.cs ├── SteamVRLib_UnityEngine.XR.Management.csproj ├── XRConfigurationData.cs ├── XRManagementAnalytics.cs ├── XRLoader.cs └── XRLoaderHelper.cs ├── LICENSE ├── README.ja.md ├── HC_VRTrial.sln └── README.md /Scripts/.gitignore: -------------------------------------------------------------------------------- 1 | package 2 | *.zip 3 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_DefaultAction.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_DefaultActionSet.cs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /packages 2 | bin 3 | obj 4 | .vs 5 | *.csproj.user 6 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_References.cs: -------------------------------------------------------------------------------- 1 | //removed -------------------------------------------------------------------------------- /HC_VRTrial/AssetBundles/.gitignore: -------------------------------------------------------------------------------- 1 | AssetBundles 2 | *.manifest 3 | *.meta 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.csproj text eol=crlf 2 | *.sln text eol=crlf 3 | *.cs text eol=crlf 4 | -------------------------------------------------------------------------------- /HC_VRTrial/AssetBundles/custom_asset_bundle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toydev/HC_VRTrial/HEAD/HC_VRTrial/AssetBundles/custom_asset_bundle -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/x64/openvr_api.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toydev/HC_VRTrial/HEAD/SteamVRLib_Unity.XR.OpenVR/x64/openvr_api.dll -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/x64/ucrtbased.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toydev/HC_VRTrial/HEAD/SteamVRLib_Unity.XR.OpenVR/x64/ucrtbased.dll -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/x64/XRSDKOpenVR.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toydev/HC_VRTrial/HEAD/SteamVRLib_Unity.XR.OpenVR/x64/XRSDKOpenVR.dll -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/Plugins/JSON.NET/Valve.Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/toydev/HC_VRTrial/HEAD/SteamVRLib_Valve.VR/SteamVR/Input/Plugins/JSON.NET/Valve.Newtonsoft.Json.dll -------------------------------------------------------------------------------- /Scripts/variables.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | SET HC_VRTrial_SOLUTION_DIR="%CD%\.." 4 | SET HC_VRTrial_DEBUG_OUTPUT_DIR="%HC_VRTrial_SOLUTION_DIR%\HC_VRTrial\bin\Debug\net6.0" 5 | SET HC_VRTrial_RELEASE_OUTPUT_DIR="%HC_VRTrial_SOLUTION_DIR%\HC_VRTrial\bin\Release\net6.0" 6 | SET HC_VRTrial_PACKAGE_DIR="%CD%\package" 7 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_ActionScopes.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | 4 | namespace Valve.VR 5 | { 6 | public enum SteamVR_Input_ActionScopes 7 | { 8 | ActionSet, 9 | Application, 10 | Global, 11 | } 12 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_ActionSetUsages.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | 4 | namespace Valve.VR 5 | { 6 | public enum SteamVR_Input_ActionSetUsages 7 | { 8 | LeftRight, 9 | Single, 10 | Hidden, 11 | } 12 | } -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/DeviceLayouts.cs: -------------------------------------------------------------------------------- 1 | #if ENABLE_VR && UNITY_INPUT_SYSTEM && !PACKAGE_DOCS_GENERATION 2 | using UnityEngine.InputSystem; 3 | using UnityEngine.InputSystem.Controls; 4 | using UnityEngine.InputSystem.Layouts; 5 | using UnityEngine.InputSystem.XR; 6 | using UnityEngine.Scripting; 7 | 8 | namespace Unity.XR.OpenVR 9 | { 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_SingleEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | 5 | namespace Valve.VR 6 | { 7 | [Serializable] 8 | public class SteamVR_Behaviour_SingleEvent : SteamVR_Events.Event { } 9 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_BooleanEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | using System; 3 | using UnityEngine.Events; 4 | 5 | namespace Valve.VR 6 | { 7 | [Serializable] 8 | public class SteamVR_Behaviour_BooleanEvent : UnityEvent { } 9 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_PoseEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_PoseEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_SkeletonEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_SkeletonEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_ActionDirections.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | namespace Valve.VR 4 | { 5 | /// 6 | /// The direction the the action. In actions get input, Out actions send input. 7 | /// 8 | public enum SteamVR_ActionDirections 9 | { 10 | In, 11 | Out, 12 | } 13 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Vector2Event.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Vector2Event : SteamVR_Events.Event { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Vector3Event.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Vector3Event : SteamVR_Events.Event { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_UpdateModes.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | 4 | namespace Valve.VR 5 | { 6 | public enum SteamVR_UpdateModes 7 | { 8 | Nothing = (1 << 0), 9 | OnUpdate = (1 << 1), 10 | OnFixedUpdate = (1 << 2), 11 | OnPreCull = (1 << 3), 12 | OnLateUpdate = (1 << 4), 13 | } 14 | } -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/UnitySubsystemsManifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "XRSDKOpenVR", 3 | "version": "1.0.0-preview.1", 4 | "libraryName": "XRSDKOpenVR", 5 | 6 | "displays": [ 7 | { 8 | "id": "OpenVR Display" 9 | } 10 | ], 11 | "inputs": [ 12 | { 13 | "id": "OpenVR Input", 14 | "disablesLegacyInput": true, 15 | "disablesLegacyVr" : true 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Pose_ConnectedChangedEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Pose_ConnectedChangedEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Pose_DeviceIndexChangedEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Pose_DeviceIndexChangedEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Pose_TrackingChangedEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Pose_TrackingChangedEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Skeleton_ConnectedChangedEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Skeleton_ConnectedChangedEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/BehaviourUnityEvents/SteamVR_Behaviour_Skeleton_TrackingChangedEvent.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine.Events; 5 | 6 | namespace Valve.VR 7 | { 8 | [Serializable] 9 | public class SteamVR_Behaviour_Skeleton_TrackingChangedEvent : UnityEvent { } 10 | } -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/Subsystem/IntegratedSubsystemExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | using UnityEngine; 4 | 5 | namespace UnityEngineExtensions 6 | { 7 | public static class IntegratedSubsystemExtensions 8 | { 9 | public static void Destroy(IntegratedSubsystem subsystem) 10 | { 11 | var ptr = subsystem.m_Ptr; 12 | SubsystemManagerExtensions.RemoveIntegratedSubsystemByPtr(subsystem.m_Ptr); 13 | SubsystemBindings.DestroySubsystem(ptr); 14 | subsystem.m_Ptr = IntPtr.Zero; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_vive_tracker_camera.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info" : {}, 3 | "bindings": { 4 | "/actions/mixedreality": { 5 | "haptics": [ 6 | ], 7 | "poses": [ 8 | { 9 | "output": "/actions/mixedreality/in/ExternalCamera", 10 | "path": "/user/camera/pose/raw" 11 | } 12 | ], 13 | "sources": [ 14 | ] 15 | } 16 | }, 17 | "controller_type" : "vive_tracker_camera", 18 | "description" : "", 19 | "name" : "tracker_forcamera", 20 | "options" : {}, 21 | "simulated_actions" : [] 22 | } 23 | -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/UIScreenPanel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace HC_VRTrial.VRUtils 4 | { 5 | public class UIScreenPanel 6 | { 7 | public UIScreenPanel(RenderTexture texture) 8 | { 9 | Texture = texture; 10 | } 11 | 12 | public UIScreenPanel(RenderTexture texture, Vector3 offset, Vector3 scale) 13 | { 14 | Texture = texture; 15 | Offset = offset; 16 | Scale = scale; 17 | } 18 | 19 | public RenderTexture Texture { get; private set; } 20 | public Vector3 Offset { get; private set; } = Vector3.zero; 21 | public Vector3 Scale { get; private set; } = Vector3.one; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_index_hmd.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info": {}, 3 | "bindings": { 4 | "/actions/default": { 5 | "chords": [], 6 | "haptics": [], 7 | "poses": [], 8 | "skeleton": [], 9 | "sources": [ 10 | { 11 | "inputs": { 12 | "click": { 13 | "output": "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode": "button", 17 | "path": "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type": "indexhmd", 23 | "description": "", 24 | "name": "index hmd defaults", 25 | "options": {}, 26 | "simulated_actions": [] 27 | } 28 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_vive_cosmos.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info": {}, 3 | "bindings": { 4 | "/actions/default": { 5 | "chords": [], 6 | "haptics": [], 7 | "poses": [], 8 | "skeleton": [], 9 | "sources": [ 10 | { 11 | "inputs": { 12 | "click": { 13 | "output": "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode": "button", 17 | "path": "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type": "vive_cosmos", 23 | "description": "", 24 | "name": "vive cosmos hmd defaults", 25 | "options": {}, 26 | "simulated_actions": [] 27 | } 28 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/Subsystem/IntegratedSubsystemDescriptorExtensions.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace UnityEngineExtensions 4 | { 5 | public static class IntegratedSubsystemDescriptorExtensions 6 | { 7 | public static IntegratedSubsystem Create(IntegratedSubsystemDescriptor integratedSubsystem) 8 | { 9 | var ptr = SubsystemDescriptorBindings.Create(integratedSubsystem.m_Ptr); 10 | var val = SubsystemManager.GetIntegratedSubsystemByPtr(ptr); 11 | if (val != null) 12 | { 13 | val.m_SubsystemDescriptor = integratedSubsystem.Cast(); 14 | } 15 | return val; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_rift.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info" : {}, 3 | "bindings" : { 4 | "/actions/default" : { 5 | "chords" : [], 6 | "haptics" : [], 7 | "poses" : [], 8 | "skeleton" : [], 9 | "sources" : [ 10 | { 11 | "inputs" : { 12 | "click" : { 13 | "output" : "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode" : "button", 17 | "path" : "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type" : "rift", 23 | "description" : "", 24 | "name" : "rift defaults", 25 | "options" : {}, 26 | "simulated_actions" : [] 27 | } 28 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_vive.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info" : {}, 3 | "bindings" : { 4 | "/actions/default" : { 5 | "chords" : [], 6 | "haptics" : [], 7 | "poses" : [], 8 | "skeleton" : [], 9 | "sources" : [ 10 | { 11 | "inputs" : { 12 | "click" : { 13 | "output" : "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode" : "button", 17 | "path" : "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type" : "vive", 23 | "description" : "", 24 | "name" : "vive defaults", 25 | "options" : {}, 26 | "simulated_actions" : [] 27 | } 28 | -------------------------------------------------------------------------------- /HC_VRTrial/AssetBundles/UI-Unlit-Transparent.shader: -------------------------------------------------------------------------------- 1 | // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt) 2 | 3 | Shader "UI/Unlit/Transparent" 4 | { 5 | Properties 6 | { 7 | _MainTex ("Base (RGB), Alpha (A)", 2D) = "white" {} 8 | _Color ("Tint", Color) = (1,1,1,1) 9 | 10 | _StencilComp ("Stencil Comparison", Float) = 8 11 | _Stencil ("Stencil ID", Float) = 0 12 | _StencilOp ("Stencil Operation", Float) = 0 13 | _StencilWriteMask ("Stencil Write Mask", Float) = 255 14 | _StencilReadMask ("Stencil Read Mask", Float) = 255 15 | 16 | _ColorMask ("Color Mask", Float) = 15 17 | 18 | [Toggle(UNITY_UI_ALPHACLIP)] _UseUIAlphaClip ("Use Alpha Clip", Float) = 0 19 | } 20 | FallBack "UI/Default" 21 | } 22 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_vive_pro.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info" : {}, 3 | "bindings" : { 4 | "/actions/default" : { 5 | "chords" : [], 6 | "haptics" : [], 7 | "poses" : [], 8 | "skeleton" : [], 9 | "sources" : [ 10 | { 11 | "inputs" : { 12 | "click" : { 13 | "output" : "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode" : "button", 17 | "path" : "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type" : "vive_pro", 23 | "description" : "", 24 | "name" : "vive_pro defaults", 25 | "options" : {}, 26 | "simulated_actions" : [] 27 | } 28 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/binding_holographic_hmd.json: -------------------------------------------------------------------------------- 1 | { 2 | "alias_info" : {}, 3 | "bindings" : { 4 | "/actions/default" : { 5 | "chords" : [], 6 | "haptics" : [], 7 | "poses" : [], 8 | "skeleton" : [], 9 | "sources" : [ 10 | { 11 | "inputs" : { 12 | "click" : { 13 | "output" : "/actions/default/in/headsetonhead" 14 | } 15 | }, 16 | "mode" : "button", 17 | "path" : "/user/head/proximity" 18 | } 19 | ] 20 | } 21 | }, 22 | "controller_type" : "holographic_hmd", 23 | "description" : "", 24 | "name" : "holographic_hmd defaults", 25 | "options" : {}, 26 | "simulated_actions" : [] 27 | } 28 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_CameraFlip.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Flips the camera output back to normal for D3D. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | // [ExecuteInEditMode] 12 | public class SteamVR_CameraFlip : MonoBehaviour 13 | { 14 | static SteamVR_CameraFlip() 15 | { 16 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 17 | } 18 | 19 | void Awake() 20 | { 21 | Debug.Log("[SteamVR] SteamVR_CameraFlip is deprecated in Unity 5.4 - REMOVING"); 22 | DestroyImmediate(this); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/XR/Settings/OpenVRSettings.asset: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!114 &11400000 4 | MonoBehaviour: 5 | m_ObjectHideFlags: 0 6 | m_CorrespondingSourceObject: {fileID: 0} 7 | m_PrefabInstance: {fileID: 0} 8 | m_PrefabAsset: {fileID: 0} 9 | m_GameObject: {fileID: 0} 10 | m_Enabled: 1 11 | m_EditorHideFlags: 0 12 | m_Script: {fileID: 11500000, guid: 7a32bfe54d957ec4581fa4a630f1647a, type: 3} 13 | m_Name: Open VR Settings 14 | m_EditorClassIdentifier: 15 | PromptToUpgradePackage: 1 16 | PromptToUpgradePreviewPackages: 1 17 | SkipPromptForVersion: 18 | StereoRenderingMode: 0 19 | InitializationType: 1 20 | EditorAppKey: application.generated.unity.steamvrunity.2044760832.exe 21 | ActionManifestFileRelativeFilePath: StreamingAssets\SteamVR\actions.json 22 | MirrorView: 2 23 | HasCopiedDefaults: 0 24 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_CameraMask.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Masks out pixels that cannot be seen through the connected hmd. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | // [ExecuteInEditMode] 12 | public class SteamVR_CameraMask : MonoBehaviour 13 | { 14 | static SteamVR_CameraMask() 15 | { 16 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 17 | } 18 | 19 | void Awake() 20 | { 21 | Debug.Log("[SteamVR] SteamVR_CameraMask is deprecated in Unity 5.4 - REMOVING"); 22 | DestroyImmediate(this); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Action_Out.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | 5 | namespace Valve.VR 6 | { 7 | [Serializable] 8 | public abstract class SteamVR_Action_Out : SteamVR_Action, ISteamVR_Action_Out 9 | where SourceMap : SteamVR_Action_Source_Map, new() 10 | where SourceElement : SteamVR_Action_Out_Source, new() 11 | { 12 | } 13 | 14 | public abstract class SteamVR_Action_Out_Source : SteamVR_Action_Source, ISteamVR_Action_Out_Source 15 | { 16 | } 17 | 18 | public interface ISteamVR_Action_Out : ISteamVR_Action, ISteamVR_Action_Out_Source 19 | { 20 | } 21 | 22 | public interface ISteamVR_Action_Out_Source : ISteamVR_Action_Source 23 | { 24 | } 25 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/ActionSetClasses/SteamVR_Input_ActionSet_mixedreality.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public class SteamVR_Input_ActionSet_mixedreality : Valve.VR.SteamVR_ActionSet 14 | { 15 | 16 | public virtual SteamVR_Action_Pose ExternalCamera 17 | { 18 | get 19 | { 20 | return SteamVR_Actions.mixedreality_ExternalCamera; 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/IXRLoaderPreInit.cs: -------------------------------------------------------------------------------- 1 | #if UNITY_EDITOR 2 | using UnityEditor; 3 | 4 | namespace UnityEngine.XR.Management 5 | { 6 | /// 7 | /// XRLoader interface for retrieving the XR PreInit library name from an XRLoader instance 8 | /// 9 | public interface IXRLoaderPreInit 10 | { 11 | /// 12 | /// Get the library name, if any, to use for XR PreInit. 13 | /// 14 | /// 15 | /// An enum specifying which platform this build is for. 16 | /// An enum specifying which platform group this build is for. 17 | /// A string specifying the library name used for XR PreInit. 18 | string GetPreInitLibraryName(BuildTarget buildTarget, BuildTargetGroup buildTargetGroup); 19 | } 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/SteamVR_Input_Initialization.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public partial class SteamVR_Actions 14 | { 15 | 16 | public static void PreInitialize() 17 | { 18 | SteamVR_Actions.StartPreInitActionSets(); 19 | SteamVR_Input.PreinitializeActionSetDictionaries(); 20 | SteamVR_Actions.PreInitActions(); 21 | SteamVR_Actions.InitializeActionArrays(); 22 | SteamVR_Input.PreinitializeActionDictionaries(); 23 | SteamVR_Input.PreinitializeFinishActionSets(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/SteamVRLib_UnityEngine.XR.Management.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | disable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/ActionSetClasses/SteamVR_Input_ActionSet_platformer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public class SteamVR_Input_ActionSet_platformer : Valve.VR.SteamVR_ActionSet 14 | { 15 | 16 | public virtual SteamVR_Action_Vector2 Move 17 | { 18 | get 19 | { 20 | return SteamVR_Actions.platformer_Move; 21 | } 22 | } 23 | 24 | public virtual SteamVR_Action_Boolean Jump 25 | { 26 | get 27 | { 28 | return SteamVR_Actions.platformer_Jump; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 toydev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/Subsystem/SubsystemManagerExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace UnityEngineExtensions 2 | { 3 | public static class SubsystemManagerExtensions 4 | { 5 | public static void GetIntegratedSubsystemDescriptors(System.Collections.Generic.List descriptors) 6 | { 7 | descriptors.Clear(); 8 | foreach (var i in UnityEngine.SubsystemsImplementation.SubsystemDescriptorStore.s_IntegratedDescriptors) descriptors.Add(i); 9 | } 10 | 11 | 12 | public static void RemoveIntegratedSubsystemByPtr(System.IntPtr ptr) 13 | { 14 | 15 | for (int i = 0; i < UnityEngine.SubsystemManager.s_IntegratedSubsystems.Count; i++) 16 | { 17 | if (!(UnityEngine.SubsystemManager.s_IntegratedSubsystems[i].m_Ptr != ptr)) 18 | { 19 | UnityEngine.SubsystemManager.s_IntegratedSubsystems[i].m_Ptr = System.IntPtr.Zero; 20 | UnityEngine.SubsystemManager.s_IntegratedSubsystems.RemoveAt(i); 21 | break; 22 | } 23 | } 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /HC_VRTrial/Logging/PluginLog.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | using BepInEx.Logging; 4 | 5 | namespace HC_VRTrial.Logging 6 | { 7 | public class PluginLog 8 | { 9 | public static void Setup(ManualLogSource logger) 10 | { 11 | LogSource = logger; 12 | } 13 | 14 | private static ManualLogSource LogSource { get; set; } 15 | 16 | public static void Debug(object data) 17 | { 18 | LogSource.LogDebug(Format(data)); 19 | } 20 | 21 | public static void Info(object data) 22 | { 23 | LogSource.LogInfo(Format(data)); 24 | } 25 | 26 | public static void Warning(object data) 27 | { 28 | LogSource.LogWarning(Format(data)); 29 | } 30 | 31 | public static void Error(object data) 32 | { 33 | LogSource.LogError(Format(data)); 34 | } 35 | 36 | private static string Format(object data) 37 | { 38 | var methodBase = new StackTrace().GetFrame(2)?.GetMethod(); 39 | var className = methodBase?.ReflectedType?.Name; 40 | var methodName = methodBase?.Name; 41 | return $"[{className}.{methodName}] {data}"; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/CustomAssetManager.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | using UnityEngine; 4 | 5 | using HC_VRTrial.Logging; 6 | 7 | namespace HC_VRTrial.VRUtils 8 | { 9 | public class CustomAssetManager 10 | { 11 | private static AssetBundle Bundle { get; set; } 12 | public static AssetBundle GetBundle() 13 | { 14 | if (Bundle == null) 15 | { 16 | Bundle = AssetBundle.LoadFromMemory(ReadAllBytes($"{nameof(HC_VRTrial)}.AssetBundles.custom_asset_bundle")); 17 | foreach (var i in Bundle.GetAllAssetNames()) PluginLog.Debug($"Available custom_asset: {i}"); 18 | } 19 | return Bundle; 20 | } 21 | 22 | public static Shader UiUnlitTransparentShader { get => GetBundle().LoadAsset("assets/assetbundles/ui-unlit-transparent.shader").Cast(); } 23 | 24 | private static byte[] ReadAllBytes(string resourceName) 25 | { 26 | var assembly = typeof(CustomAssetManager).Assembly; 27 | using (var stream = assembly.GetManifestResourceStream(resourceName)) 28 | using (var memoryStream = new MemoryStream()) 29 | { 30 | stream.CopyTo(memoryStream); 31 | return memoryStream.ToArray(); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_Generator_Names.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | 4 | namespace Valve.VR 5 | { 6 | public class SteamVR_Input_Generator_Names 7 | { 8 | public const string fullActionsClassName = "Valve.VR.SteamVR_Actions"; 9 | public const string actionsClassName = "SteamVR_Actions"; 10 | 11 | public const string preinitializeMethodName = "PreInitialize"; 12 | 13 | public const string actionsFieldName = "actions"; 14 | public const string actionsInFieldName = "actionsIn"; 15 | public const string actionsOutFieldName = "actionsOut"; 16 | public const string actionsVibrationFieldName = "actionsVibration"; 17 | public const string actionsPoseFieldName = "actionsPose"; 18 | public const string actionsBooleanFieldName = "actionsBoolean"; 19 | public const string actionsSingleFieldName = "actionsSingle"; 20 | public const string actionsVector2FieldName = "actionsVector2"; 21 | public const string actionsVector3FieldName = "actionsVector3"; 22 | public const string actionsSkeletonFieldName = "actionsSkeleton"; 23 | public const string actionsNonPoseNonSkeletonIn = "actionsNonPoseNonSkeletonIn"; 24 | public const string actionSetsFieldName = "actionSets"; 25 | } 26 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_Sources.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System.ComponentModel; 4 | 5 | namespace Valve.VR 6 | { 7 | public enum SteamVR_Input_Sources 8 | { 9 | [Description("/unrestricted")] //todo: check to see if this gets exported: k_ulInvalidInputHandle 10 | Any, 11 | 12 | [Description("/user/hand/left")] 13 | LeftHand, 14 | 15 | [Description("/user/hand/right")] 16 | RightHand, 17 | 18 | [Description("/user/foot/left")] 19 | LeftFoot, 20 | 21 | [Description("/user/foot/right")] 22 | RightFoot, 23 | 24 | [Description("/user/shoulder/left")] 25 | LeftShoulder, 26 | 27 | [Description("/user/shoulder/right")] 28 | RightShoulder, 29 | 30 | [Description("/user/waist")] 31 | Waist, 32 | 33 | [Description("/user/chest")] 34 | Chest, 35 | 36 | [Description("/user/head")] 37 | Head, 38 | 39 | [Description("/user/gamepad")] 40 | Gamepad, 41 | 42 | [Description("/user/camera")] 43 | Camera, 44 | 45 | [Description("/user/keyboard")] 46 | Keyboard, 47 | 48 | [Description("/user/treadmill")] 49 | Treadmill, 50 | } 51 | } 52 | 53 | namespace Valve.VR.InputSources 54 | { 55 | using Sources = SteamVR_Input_Sources; 56 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/ActionSetClasses/SteamVR_Input_ActionSet_buggy.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public class SteamVR_Input_ActionSet_buggy : Valve.VR.SteamVR_ActionSet 14 | { 15 | 16 | public virtual SteamVR_Action_Vector2 Steering 17 | { 18 | get 19 | { 20 | return SteamVR_Actions.buggy_Steering; 21 | } 22 | } 23 | 24 | public virtual SteamVR_Action_Single Throttle 25 | { 26 | get 27 | { 28 | return SteamVR_Actions.buggy_Throttle; 29 | } 30 | } 31 | 32 | public virtual SteamVR_Action_Boolean Brake 33 | { 34 | get 35 | { 36 | return SteamVR_Actions.buggy_Brake; 37 | } 38 | } 39 | 40 | public virtual SteamVR_Action_Boolean Reset 41 | { 42 | get 43 | { 44 | return SteamVR_Actions.buggy_Reset; 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/SteamVRLib_Unity.XR.OpenVR.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | enable 5 | disable 6 | 7 | 8 | 9 | $(DefineConstants);UNITY_5_3_OR_NEWER;UNITY_XR_MANAGEMENT 10 | 11 | 12 | 13 | $(DefineConstants);UNITY_5_3_OR_NEWER;UNITY_XR_MANAGEMENT 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_EnumEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq.Expressions; 6 | 7 | namespace Valve.VR 8 | { 9 | struct SteamVREnumEqualityComparer : IEqualityComparer where TEnum : struct 10 | { 11 | static class BoxAvoidance 12 | { 13 | static readonly Func _wrapper; 14 | 15 | public static int ToInt(TEnum enu) 16 | { 17 | return _wrapper(enu); 18 | } 19 | 20 | static BoxAvoidance() 21 | { 22 | var p = Expression.Parameter(typeof(TEnum), null); 23 | var c = Expression.ConvertChecked(p, typeof(int)); 24 | 25 | _wrapper = Expression.Lambda>(c, p).Compile(); 26 | } 27 | } 28 | 29 | public bool Equals(TEnum firstEnum, TEnum secondEnum) 30 | { 31 | return BoxAvoidance.ToInt(firstEnum) == BoxAvoidance.ToInt(secondEnum); 32 | } 33 | 34 | public int GetHashCode(TEnum firstEnum) 35 | { 36 | return BoxAvoidance.ToInt(firstEnum); 37 | } 38 | } 39 | 40 | public struct SteamVR_Input_Sources_Comparer : IEqualityComparer 41 | { 42 | public bool Equals(SteamVR_Input_Sources x, SteamVR_Input_Sources y) 43 | { 44 | return x == y; 45 | } 46 | 47 | public int GetHashCode(SteamVR_Input_Sources obj) 48 | { 49 | return (int)obj; 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_ActivateActionSetOnLoad.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | /// 8 | /// Automatically activates an action set on Start() and deactivates the set on OnDestroy(). Optionally deactivating all other sets as well. 9 | /// 10 | public class SteamVR_ActivateActionSetOnLoad : MonoBehaviour 11 | { 12 | static SteamVR_ActivateActionSetOnLoad() 13 | { 14 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 15 | } 16 | 17 | public SteamVR_ActionSet actionSet = SteamVR_Input.GetActionSet("default"); 18 | 19 | public SteamVR_Input_Sources forSources = SteamVR_Input_Sources.Any; 20 | 21 | public bool disableAllOtherActionSets = false; 22 | 23 | public bool activateOnStart = true; 24 | public bool deactivateOnDestroy = true; 25 | 26 | public int initialPriority = 0; 27 | 28 | private void Start() 29 | { 30 | if (actionSet != null && activateOnStart) 31 | { 32 | //Debug.Log(string.Format("[SteamVR] Activating {0} action set.", actionSet.fullPath)); 33 | actionSet.Activate(forSources, initialPriority, disableAllOtherActionSets); 34 | } 35 | } 36 | 37 | private void OnDestroy() 38 | { 39 | if (actionSet != null && deactivateOnDestroy) 40 | { 41 | //Debug.Log(string.Format("[SteamVR] Deactivating {0} action set.", actionSet.fullPath)); 42 | actionSet.Deactivate(forSources); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_ExternalCamera_LegacyManager.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Used to render an external camera of vr player (split front/back). 4 | // 5 | //============================================================================= 6 | 7 | namespace Valve.VR 8 | { 9 | public class SteamVR_ExternalCamera_LegacyManager 10 | { 11 | public static bool hasCamera { get { return cameraIndex != -1; } } 12 | 13 | public static int cameraIndex = -1; 14 | 15 | private static SteamVR_Events.Action newPosesAction = null; 16 | 17 | public static void SubscribeToNewPoses() 18 | { 19 | if (newPosesAction == null) 20 | newPosesAction = SteamVR_Events.NewPosesAction(OnNewPoses); 21 | 22 | newPosesAction.enabled = true; 23 | } 24 | 25 | private static void OnNewPoses(TrackedDevicePose_t[] poses) 26 | { 27 | if (cameraIndex != -1) 28 | return; 29 | 30 | int controllercount = 0; 31 | for (int index = 0; index < poses.Length; index++) 32 | { 33 | if (poses[index].bDeviceIsConnected) 34 | { 35 | ETrackedDeviceClass deviceClass = OpenVR.System.GetTrackedDeviceClass((uint)index); 36 | if (deviceClass == ETrackedDeviceClass.Controller || deviceClass == ETrackedDeviceClass.GenericTracker) 37 | { 38 | controllercount++; 39 | if (controllercount >= 3) 40 | { 41 | cameraIndex = index; 42 | break; 43 | } 44 | } 45 | } 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /Scripts/clean_debug_env.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SETLOCAL 3 | 4 | CALL variables.bat 5 | 6 | CALL :CLEAN "%HC_VRTrial_GAME_HOME%\BepInEx\plugins\HC_VRTrial" "%HC_VRTrial_GAME_HOME%\HoneyCome_Data" 7 | CALL :CLEAN "%HC_VRTrial_GAME_HOME%\DigitalCraft\BepInEx\plugins\HC_VRTrial" "%HC_VRTrial_GAME_HOME%\DigitalCraft\DigitalCraft_Data" 8 | 9 | IF "%1" NEQ "called" PAUSE 10 | 11 | GOTO :EOF 12 | 13 | REM ==================== Clean 14 | :CLEAN 15 | 16 | SET PLUGIN_DIR=%1 17 | SET GAME_DATA_DIR=%2 18 | 19 | REM ========== plugins 20 | IF EXIST "%PLUGIN_DIR%" ( 21 | ECHO DELETE %PLUGIN_DIR% 22 | RMDIR /s /q "%PLUGIN_DIR%" 23 | ) 24 | 25 | REM ========== Data 26 | REM DLL files 27 | IF EXIST "%GAME_DATA_DIR%\Plugins\x86_64\openvr_api.dll" ( 28 | ECHO DELETE %GAME_DATA_DIR%\Plugins\x86_64\openvr_api.dll 29 | DEL "%GAME_DATA_DIR%\Plugins\x86_64\openvr_api.dll" 30 | ) 31 | 32 | IF EXIST "%GAME_DATA_DIR%\Plugins\x86_64\XRSDKOpenVR.dll" ( 33 | ECHO DELETE %GAME_DATA_DIR%\Plugins\x86_64\XRSDKOpenVR.dll 34 | DEL "%GAME_DATA_DIR%\Plugins\x86_64\XRSDKOpenVR.dll" 35 | ) 36 | 37 | REM SteamVR Input action files 38 | IF EXIST "%GAME_DATA_DIR%\StreamingAssets\SteamVR\*.json" ( 39 | ECHO DELETE %GAME_DATA_DIR%\StreamingAssets\SteamVR\*.json 40 | DEL "%GAME_DATA_DIR%\StreamingAssets\SteamVR\*.json" 41 | ) 42 | 43 | REM OpenVRSettings.asset 44 | IF EXIST "%GAME_DATA_DIR%\StreamingAssets\SteamVR\OpenVRSettings.asset" ( 45 | ECHO DELETE %GAME_DATA_DIR%\StreamingAssets\SteamVR\OpenVRSettings.asset 46 | DEL "%GAME_DATA_DIR%\StreamingAssets\SteamVR\OpenVRSettings.asset" 47 | ) 48 | 49 | REM UnitySubsystemsManifest.json 50 | IF EXIST "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR\UnitySubsystemsManifest.json" ( 51 | ECHO DELETE %GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR\UnitySubsystemsManifest.json 52 | DEL "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR\UnitySubsystemsManifest.json" 53 | ) 54 | 55 | GOTO :EOF 56 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_SphericalProjection.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Applies spherical projection to output. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | // [ExecuteInEditMode] 12 | public class SteamVR_SphericalProjection : MonoBehaviour 13 | { 14 | static SteamVR_SphericalProjection() 15 | { 16 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 17 | } 18 | 19 | static Material material; 20 | 21 | public void Set(Vector3 N, 22 | float phi0, float phi1, float theta0, float theta1, // in degrees 23 | Vector3 uAxis, Vector3 uOrigin, float uScale, 24 | Vector3 vAxis, Vector3 vOrigin, float vScale) 25 | { 26 | if (material == null) 27 | material = new Material(Shader.Find("Custom/SteamVR_SphericalProjection")); 28 | 29 | material.SetVector("_N", new Vector4(N.x, N.y, N.z)); 30 | material.SetFloat("_Phi0", phi0 * Mathf.Deg2Rad); 31 | material.SetFloat("_Phi1", phi1 * Mathf.Deg2Rad); 32 | material.SetFloat("_Theta0", theta0 * Mathf.Deg2Rad + Mathf.PI / 2); 33 | material.SetFloat("_Theta1", theta1 * Mathf.Deg2Rad + Mathf.PI / 2); 34 | material.SetVector("_UAxis", uAxis); 35 | material.SetVector("_VAxis", vAxis); 36 | material.SetVector("_UOrigin", uOrigin); 37 | material.SetVector("_VOrigin", vOrigin); 38 | material.SetFloat("_UScale", uScale); 39 | material.SetFloat("_VScale", vScale); 40 | } 41 | 42 | void OnRenderImage(RenderTexture src, RenderTexture dest) 43 | { 44 | Graphics.Blit(src, dest, material); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /HC_VRTrial/Plugin.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using System.Linq; 3 | 4 | using BepInEx; 5 | using BepInEx.Unity.IL2CPP; 6 | using Il2CppInterop.Runtime; 7 | using UnityEngine; 8 | using UnityEngine.SceneManagement; 9 | 10 | using HC_VRTrial.Logging; 11 | using HC_VRTrial.VRUtils; 12 | using UnityEngine.Events; 13 | 14 | namespace HC_VRTrial 15 | { 16 | [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] 17 | public class Plugin : BasePlugin 18 | { 19 | public override void Load() 20 | { 21 | PluginLog.Setup(Log); 22 | PluginConfig.Setup(Config); 23 | 24 | // Log some information debugging purposes. 25 | for (var i = 0; i < 32; ++i) PluginLog.Debug($"Available layers - Layer[{i}]: {LayerMask.LayerToName(i)}"); 26 | foreach (var i in Resources.FindObjectsOfTypeAll(Il2CppType.From(typeof(Shader)))) PluginLog.Debug($"Available shader: {i.name}"); 27 | 28 | // Initialize VR if the SteamVR process is running. 29 | if (IsSteamVRRunning) 30 | { 31 | VR.Initialize(() => 32 | { 33 | SceneManager.sceneLoaded += (UnityAction)OnSceneLoaded; 34 | }); 35 | } 36 | } 37 | 38 | public void OnSceneLoaded(Scene scene, LoadSceneMode mode) 39 | { 40 | // Detects a single mode scene and starts VR control of the scene. 41 | if (mode == LoadSceneMode.Single) 42 | { 43 | new GameObject($"{nameof(SimpleVRController)}{scene.name}").AddComponent(); 44 | } 45 | } 46 | 47 | /// 48 | /// Checks if the SteamVR compositor process is currently running. Used to determine if VR initialization is necessary. 49 | /// 50 | private bool IsSteamVRRunning => Process.GetProcesses().Any(i => i.ProcessName == "vrcompositor"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_Ears.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Handles aligning audio listener when using speakers. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | // [RequireComponent(typeof(AudioListener))] 12 | public class SteamVR_Ears : MonoBehaviour 13 | { 14 | static SteamVR_Ears() 15 | { 16 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 17 | } 18 | 19 | public SteamVR_Camera vrcam; 20 | 21 | bool usingSpeakers; 22 | Quaternion offset; 23 | 24 | private void OnNewPosesApplied() 25 | { 26 | var origin = vrcam.origin; 27 | var baseRotation = origin != null ? origin.rotation : Quaternion.identity; 28 | transform.rotation = baseRotation * offset; 29 | } 30 | 31 | void OnEnable() 32 | { 33 | usingSpeakers = false; 34 | 35 | var settings = OpenVR.Settings; 36 | if (settings != null) 37 | { 38 | var error = EVRSettingsError.None; 39 | if (settings.GetBool(OpenVR.k_pch_SteamVR_Section, OpenVR.k_pch_SteamVR_UsingSpeakers_Bool, ref error)) 40 | { 41 | usingSpeakers = true; 42 | 43 | var yawOffset = settings.GetFloat(OpenVR.k_pch_SteamVR_Section, OpenVR.k_pch_SteamVR_SpeakersForwardYawOffsetDegrees_Float, ref error); 44 | offset = Quaternion.Euler(0.0f, yawOffset, 0.0f); 45 | } 46 | } 47 | 48 | if (usingSpeakers) 49 | SteamVR_Events.NewPosesApplied.Listen(OnNewPosesApplied); 50 | } 51 | 52 | void OnDisable() 53 | { 54 | if (usingSpeakers) 55 | SteamVR_Events.NewPosesApplied.Remove(OnNewPosesApplied); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVRLib_Valve.VR.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net6.0 4 | disable 5 | disable 6 | 7 | 8 | 9 | $(DefineConstants);UNITY_5_3_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2019_3_OR_NEWER;OPENVR_XR_API;UNITY_URP 10 | 11 | 12 | 13 | $(DefineConstants);UNITY_5_3_OR_NEWER;UNITY_2017_1_OR_NEWER;UNITY_2017_2_OR_NEWER;UNITY_2018_3_OR_NEWER;UNITY_2019_3_OR_NEWER;OPENVR_XR_API;UNITY_URP 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/XRConfigurationData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace UnityEngine.XR.Management 4 | { 5 | /// 6 | /// This attribute is used to tag classes as providing build settings support for an XR provider. The unified setting system 7 | /// will present the settings as an inspectable object in the Unified Settings window using the built-in inspector UI. 8 | /// 9 | /// The implementor of the settings is able to create their own custom UI and the Unified Settings system will use that UI in 10 | /// place of the build in inspector. See the <a href="https://docs.unity3d.com/Manual/ExtendingTheEditor.html">>Extending the Editor</a> 11 | /// portion of the Unity documentation for information and instructions on doing this. 12 | /// 13 | [AttributeUsage(AttributeTargets.Class)] 14 | public sealed class XRConfigurationDataAttribute : Attribute 15 | { 16 | /// 17 | /// The display name to be presented to the user in the Unified Settings window. 18 | /// 19 | public string displayName { get; set; } 20 | 21 | /// 22 | /// The key that will be used to store the singleton instance of these settings within EditorBuildSettings. 23 | /// 24 | /// See <a href="https://docs.unity3d.com/ScriptReference/EditorBuildSettings.html">EditorBuildSettings</a> scripting 25 | /// API documentation on how this is beign done. 26 | /// 27 | public string buildSettingsKey { get; set; } 28 | 29 | private XRConfigurationDataAttribute() {} 30 | 31 | /// Constructor for attribute 32 | /// The display name to use in the Project Settings window. 33 | /// The key to use to get/set build settings with. 34 | public XRConfigurationDataAttribute(string displayName, string buildSettingsKey) 35 | { 36 | this.displayName = displayName; 37 | this.buildSettingsKey = buildSettingsKey; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Scripts/setup_debug_env.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SETLOCAL 3 | 4 | CALL variables.bat 5 | 6 | CALL clean_debug_env.bat called 7 | 8 | CALL :SETUP "%HC_VRTrial_GAME_HOME%\BepInEx\plugins" "%HC_VRTrial_GAME_HOME%\HoneyCome_Data" 9 | CALL :SETUP "%HC_VRTrial_GAME_HOME%\DigitalCraft\BepInEx\plugins" "%HC_VRTrial_GAME_HOME%\DigitalCraft\DigitalCraft_Data" 10 | 11 | PAUSE 12 | 13 | GOTO :EOF 14 | 15 | REM ==================== Setup 16 | :SETUP 17 | 18 | SET PLUGIN_DIR=%1 19 | SET GAME_DATA_DIR=%2 20 | 21 | REM ========== plugins 22 | IF EXIST "%PLUGIN_DIR%" ( 23 | MKDIR "%PLUGIN_DIR%"\HC_VRTrial 24 | MKLINK "%PLUGIN_DIR%\HC_VRTrial\HC_VRTrial.dll" "%HC_VRTrial_DEBUG_OUTPUT_DIR%\HC_VRTrial.dll" 25 | MKLINK "%PLUGIN_DIR%\HC_VRTrial\SteamVRLib_UnityEngine.XR.Management.dll" "%HC_VRTrial_DEBUG_OUTPUT_DIR%\SteamVRLib_UnityEngine.XR.Management.dll" 26 | MKLINK "%PLUGIN_DIR%\HC_VRTrial\SteamVRLib_Valve.VR.dll" "%HC_VRTrial_DEBUG_OUTPUT_DIR%\SteamVRLib_Valve.VR.dll" 27 | MKLINK "%PLUGIN_DIR%\HC_VRTrial\SteamVRLib_Unity.XR.OpenVR.dll" "%HC_VRTrial_DEBUG_OUTPUT_DIR%\SteamVRLib_Unity.XR.OpenVR.dll" 28 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\openvr_api.dll" "%PLUGIN_DIR%"\HC_VRTrial 29 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\XRSDKOpenVR.dll" "%PLUGIN_DIR%"\HC_VRTrial 30 | ) 31 | 32 | REM ========== Data 33 | IF EXIST "%GAME_DATA_DIR%" ( 34 | REM DLL files 35 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\openvr_api.dll" "%GAME_DATA_DIR%\Plugins\x86_64" 36 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\XRSDKOpenVR.dll" "%GAME_DATA_DIR%\Plugins\x86_64" 37 | 38 | REM SteamVR Input action files 39 | MKDIR "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 40 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Valve.VR\StreamingAssets\SteamVR\*.json" "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 41 | 42 | REM OpenVRSettings.asset 43 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Valve.VR\XR\Settings\OpenVRSettings.asset" "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 44 | 45 | REM UnitySubsystemsManifest.json 46 | MKDIR "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR" 47 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\UnitySubsystemsManifest.json" "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR" 48 | ) 49 | 50 | GOTO :EOF 51 | -------------------------------------------------------------------------------- /README.ja.md: -------------------------------------------------------------------------------- 1 | [English](README.md) 2 | 3 | # VR Trial plugin for Honey Come 4 | Honey Come の VR プラグイン実験プロジェクトです。 5 | 6 | たくさんの課題があり不完全ですが、Honey Come VR の可能性を感じることができます。 7 | 8 | できそうだと感じたら課題を一緒に解決しましょう。 9 | 10 | そして、自分好みの VR プラグインの構築に挑戦しましょう。 11 | 12 | ---- 13 | 14 | ## 前提 15 | - Honey Come 16 | - 最新バージョンの [BepInEx 6.x Unity IL2CPP for Windows (x64) games](https://builds.bepinex.dev/projects/bepinex_be) 17 | - HMD(私は Meta Quest 2 を使っているが SteamVR が認識すれば基本的には動くと思う) 18 | - SteamVR 19 | - [BepisPlugins](https://github.com/IllusionMods/BepisPlugins/) 20 | - [BepInEx.ConfigurationManager](https://github.com/BepInEx/BepInEx.ConfigurationManager) 21 | - 他の VR プラグインが入っていないこと 22 | 23 | ---- 24 | 25 | ## 遊び方 26 | ゲームに [HC_VRTrial](https://github.com/toydev/HC_VRTrial/releases) をインストールし、HMD と SteamVR を接続してゲームを開始してください。 27 | 28 | 開始時に SteamVR のプロセスを検出して有効になります。 29 | 30 | ---- 31 | 32 | ## 操作 33 | 右ダブルクリックで頭の向きに合わせてビューポートを更新します。 34 | 35 | その他の操作については通常プレイ通りキーボードとマウスで操作してください。 36 | 37 | ---- 38 | 39 | ## 設定 40 | ### VRExperienceOptimization セクション 41 | |キー|デフォルト値|説明| 42 | |----|----|----| 43 | |DisableLights|true|true で全てのライトを無効にします。| 44 | |DisableLODGroups|true|true で全ての LODGroup を無効にします。| 45 | |DisableParticleSystems|true|true で ParticleNameDisableRegex に基づき特定の ParticleSystem を無効にします。| 46 | |ParticleNameDisableRegex|(?!Star\|Heart\|ef_ne)|無効にする ParticleSystem 名の正規表現パターンです。DisableParticleSystems を true にする必要があります。パターンにマッチする ParticleSystem を無効にします。| 47 | 48 | ### Viewport セクション 49 | |キー|デフォルト値|説明| 50 | |----|----|----| 51 | |DoubleClickIntervalToUpdateViewport|0.2f|ビューポート更新のダブルクリック検出のための最大秒数です。0 以下の値で無効にできます。| 52 | |ReflectHMDRotationXOnViewport|true|HMDの縦の向き(X 軸回転)をビューポートに反映させます。仰向けやうつ伏せで使う人は有効にしてください。| 53 | |ReflectHMDRotationYOnViewport|true|HMDの横の向き(Y 軸回転)をビューポートに反映させます。有効にして使うのが一般的です。| 54 | |ReflectHMDRotationZOnViewport|true|HMDの傾き(Z 軸回転)をビューポートに反映させます。横向きに寝て使う人は有効にしてください。| 55 | 56 | 以下はプレイスタイル毎の設定例です。仰向け/うつ伏せがデフォルトです。 57 | 58 | |スタイル|ReflectHMDRotationXOnViewport
HMDの縦の向き
(X 軸回転)|ReflectHMDRotationYOnViewport
HMDの横の向き
(Y 軸回転)|ReflectHMDRotationZOnViewport
HMDの傾き
(Z 軸回転)| 59 | |----|----|----|----| 60 | |座位/立位|無効|有効|無効| 61 | |仰向け/うつ伏せ(デフォルト)|有効|有効|有効| 62 | |側位|有効|有効|有効| 63 | 64 | ---- 65 | 66 | ## 開発者向け 67 | 68 | - [開発者向け wiki ホーム](https://github.com/toydev/HC_VRTrial/wiki/Home.ja) 69 | -------------------------------------------------------------------------------- /Scripts/package_release.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SETLOCAL 3 | 4 | CALL variables.bat 5 | 6 | IF EXIST "%HC_VRTrial_PACKAGE_DIR%" ( 7 | RMDIR /s /q "%HC_VRTrial_PACKAGE_DIR%" 8 | ) 9 | 10 | CALL :PACKAGE "%HC_VRTrial_PACKAGE_DIR%\BepInEx\plugins\HC_VRTrial" "%HC_VRTrial_PACKAGE_DIR%\HoneyCome_Data" 11 | CALL :PACKAGE "%HC_VRTrial_PACKAGE_DIR%\DigitalCraft\BepInEx\plugins\HC_VRTrial" "%HC_VRTrial_PACKAGE_DIR%\DigitalCraft\DigitalCraft_Data" 12 | 13 | SET RELEASE_FILE_PATH="%HC_VRTrial_PACKAGE_DIR%\..\HC_VRTrial.zip" 14 | 15 | IF EXIST "%RELEASE_FILE_PATH%" ( 16 | DEL "%RELEASE_FILE_PATH%" 17 | ) 18 | powershell Compress-Archive -Path "%HC_VRTrial_PACKAGE_DIR%\*" -DestinationPath "%RELEASE_FILE_PATH%" 19 | 20 | GOTO :EOF 21 | 22 | PAUSE 23 | 24 | REM ==================== Package 25 | :PACKAGE 26 | 27 | SET PLUGIN_DIR=%1 28 | SET GAME_DATA_DIR=%2 29 | 30 | REM ========== plugins 31 | MKDIR "%PLUGIN_DIR%" 32 | COPY "%HC_VRTrial_RELEASE_OUTPUT_DIR%\HC_VRTrial.dll" "%PLUGIN_DIR%" 33 | COPY "%HC_VRTrial_RELEASE_OUTPUT_DIR%\SteamVRLib_UnityEngine.XR.Management.dll" "%PLUGIN_DIR%" 34 | COPY "%HC_VRTrial_RELEASE_OUTPUT_DIR%\SteamVRLib_Valve.VR.dll" "%PLUGIN_DIR%" 35 | COPY "%HC_VRTrial_RELEASE_OUTPUT_DIR%\SteamVRLib_Unity.XR.OpenVR.dll" "%PLUGIN_DIR%" 36 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\openvr_api.dll" "%PLUGIN_DIR%" 37 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\XRSDKOpenVR.dll" "%PLUGIN_DIR%" 38 | 39 | REM ========== Data 40 | REM DLL files 41 | MKDIR "%GAME_DATA_DIR%\Plugins\x86_64" 42 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\openvr_api.dll" "%GAME_DATA_DIR%\Plugins\x86_64" 43 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\x64\XRSDKOpenVR.dll" "%GAME_DATA_DIR%\Plugins\x86_64" 44 | 45 | REM SteamVR Input action files 46 | MKDIR "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 47 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Valve.VR\StreamingAssets\SteamVR\*.json" "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 48 | 49 | REM OpenVRSettings.asset 50 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Valve.VR\XR\Settings\OpenVRSettings.asset" "%GAME_DATA_DIR%\StreamingAssets\SteamVR" 51 | 52 | REM UnitySubsystemsManifest.json 53 | MKDIR "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR" 54 | COPY "%HC_VRTrial_SOLUTION_DIR%\SteamVRLib_Unity.XR.OpenVR\UnitySubsystemsManifest.json" "%GAME_DATA_DIR%\UnitySubsystems\XRSDKOpenVR" 55 | 56 | GOTO :EOF 57 | -------------------------------------------------------------------------------- /HC_VRTrial/HC_VRTrial.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HC_VRTrial 5 | HC_VRTrial 6 | 1.0.2 7 | net6.0 8 | disable 9 | disable 10 | true 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /HC_VRTrial.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34221.43 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HC_VRTrial", "HC_VRTrial\HC_VRTrial.csproj", "{D41EA721-10E4-4BA3-A0C9-E0C1D5140456}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamVRLib_Unity.XR.OpenVR", "SteamVRLib_Unity.XR.OpenVR\SteamVRLib_Unity.XR.OpenVR.csproj", "{78473AD4-81C6-40D3-8603-6AF764A449AE}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamVRLib_UnityEngine.XR.Management", "SteamVRLib_UnityEngine.XR.Management\SteamVRLib_UnityEngine.XR.Management.csproj", "{253F2D9B-1ADC-45E1-9BF9-3EFED7056C26}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SteamVRLib_Valve.VR", "SteamVRLib_Valve.VR\SteamVRLib_Valve.VR.csproj", "{56FA2403-CB40-4835-A292-E7F7C53D5C63}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {D41EA721-10E4-4BA3-A0C9-E0C1D5140456}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {D41EA721-10E4-4BA3-A0C9-E0C1D5140456}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {D41EA721-10E4-4BA3-A0C9-E0C1D5140456}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {D41EA721-10E4-4BA3-A0C9-E0C1D5140456}.Release|Any CPU.Build.0 = Release|Any CPU 24 | {78473AD4-81C6-40D3-8603-6AF764A449AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {78473AD4-81C6-40D3-8603-6AF764A449AE}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {78473AD4-81C6-40D3-8603-6AF764A449AE}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {78473AD4-81C6-40D3-8603-6AF764A449AE}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {253F2D9B-1ADC-45E1-9BF9-3EFED7056C26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {253F2D9B-1ADC-45E1-9BF9-3EFED7056C26}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {253F2D9B-1ADC-45E1-9BF9-3EFED7056C26}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {253F2D9B-1ADC-45E1-9BF9-3EFED7056C26}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {56FA2403-CB40-4835-A292-E7F7C53D5C63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {56FA2403-CB40-4835-A292-E7F7C53D5C63}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {56FA2403-CB40-4835-A292-E7F7C53D5C63}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {56FA2403-CB40-4835-A292-E7F7C53D5C63}.Release|Any CPU.Build.0 = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(SolutionProperties) = preSolution 38 | HideSolutionNode = FALSE 39 | EndGlobalSection 40 | GlobalSection(ExtensibilityGlobals) = postSolution 41 | SolutionGuid = {317FBAA3-4E64-440F-ABD6-B781D4D1E364} 42 | EndGlobalSection 43 | EndGlobal 44 | -------------------------------------------------------------------------------- /HC_VRTrial/PluginConfig.cs: -------------------------------------------------------------------------------- 1 | using BepInEx.Configuration; 2 | 3 | namespace HC_VRTrial 4 | { 5 | public class PluginConfig 6 | { 7 | public static ConfigEntry DisableLights { get; private set; } 8 | public static ConfigEntry DisableLODGroups { get; private set; } 9 | public static ConfigEntry DisableParticleSystems { get; private set; } 10 | public static ConfigEntry ParticleNameDisableRegex { get; private set; } 11 | 12 | public static ConfigEntry DoubleClickIntervalToUpdateViewport { get; private set; } 13 | public static ConfigEntry ReflectHMDRotationXOnViewport { get; private set; } 14 | public static ConfigEntry ReflectHMDRotationYOnViewport { get; private set; } 15 | public static ConfigEntry ReflectHMDRotationZOnViewport { get; private set; } 16 | 17 | public static void Setup(ConfigFile config) 18 | { 19 | DisableLights = config.Bind("VRExperienceOptimization", nameof(DisableLights), true, 20 | "If true, disables all lights."); 21 | DisableLODGroups = config.Bind("VRExperienceOptimization", nameof(DisableLODGroups), true, 22 | "If true, disables all LODGroups."); 23 | DisableParticleSystems = config.Bind("VRExperienceOptimization", nameof(DisableParticleSystems), true, 24 | "If true, enables the conditional disabling of ParticleSystems based on the ParticleNameDisableRegex setting."); 25 | ParticleNameDisableRegex = config.Bind("VRExperienceOptimization", nameof(ParticleNameDisableRegex), "^(?!Star|Heart|ef_ne)", 26 | "Regex pattern to specify which ParticleSystems should be disabled. Requires DisableParticleSystems to be true. Only ParticleSystems matching this pattern will be affected."); 27 | 28 | DoubleClickIntervalToUpdateViewport = config.Bind("Viewport", nameof(DoubleClickIntervalToUpdateViewport), 0.2f, 29 | "Defines the maximum interval, in seconds, that is considered for detecting a double-click to update the viewport's orientation based on HMD rotation. Set to 0 or less to disable this feature."); 30 | ReflectHMDRotationXOnViewport = config.Bind("Viewport", nameof(ReflectHMDRotationXOnViewport), true, 31 | "Reflects the HMD's vertical orientation (X-axis rotation) on the viewport. Enable this for use while lying on your back or stomach."); 32 | ReflectHMDRotationYOnViewport = config.Bind("Viewport", nameof(ReflectHMDRotationYOnViewport), true, 33 | "Reflects the HMD's horizontal orientation (Y-axis rotation) on the viewport. It is commonly enabled for use."); 34 | ReflectHMDRotationZOnViewport = config.Bind("Viewport", nameof(ReflectHMDRotationZOnViewport), true, 35 | "Reflects the HMD's tilt (Z-axis rotation) on the viewport. Enable this for use while lying on your side."); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/SteamVR_Input_ActionSets.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public partial class SteamVR_Actions 14 | { 15 | 16 | private static SteamVR_Input_ActionSet_default p__default; 17 | 18 | private static SteamVR_Input_ActionSet_platformer p_platformer; 19 | 20 | private static SteamVR_Input_ActionSet_buggy p_buggy; 21 | 22 | private static SteamVR_Input_ActionSet_mixedreality p_mixedreality; 23 | 24 | public static SteamVR_Input_ActionSet_default _default 25 | { 26 | get 27 | { 28 | return SteamVR_Actions.p__default.GetCopy(); 29 | } 30 | } 31 | 32 | public static SteamVR_Input_ActionSet_platformer platformer 33 | { 34 | get 35 | { 36 | return SteamVR_Actions.p_platformer.GetCopy(); 37 | } 38 | } 39 | 40 | public static SteamVR_Input_ActionSet_buggy buggy 41 | { 42 | get 43 | { 44 | return SteamVR_Actions.p_buggy.GetCopy(); 45 | } 46 | } 47 | 48 | public static SteamVR_Input_ActionSet_mixedreality mixedreality 49 | { 50 | get 51 | { 52 | return SteamVR_Actions.p_mixedreality.GetCopy(); 53 | } 54 | } 55 | 56 | private static void StartPreInitActionSets() 57 | { 58 | SteamVR_Actions.p__default = ((SteamVR_Input_ActionSet_default)(SteamVR_ActionSet.Create("/actions/default"))); 59 | SteamVR_Actions.p_platformer = ((SteamVR_Input_ActionSet_platformer)(SteamVR_ActionSet.Create("/actions/platformer"))); 60 | SteamVR_Actions.p_buggy = ((SteamVR_Input_ActionSet_buggy)(SteamVR_ActionSet.Create("/actions/buggy"))); 61 | SteamVR_Actions.p_mixedreality = ((SteamVR_Input_ActionSet_mixedreality)(SteamVR_ActionSet.Create("/actions/mixedreality"))); 62 | Valve.VR.SteamVR_Input.actionSets = new Valve.VR.SteamVR_ActionSet[] { 63 | SteamVR_Actions._default, 64 | SteamVR_Actions.platformer, 65 | SteamVR_Actions.buggy, 66 | SteamVR_Actions.mixedreality}; 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/XRManagementAnalytics.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | #if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS 9 | using UnityEngine.Analytics; 10 | #endif //UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS 11 | 12 | [assembly:InternalsVisibleTo("Unity.XR.Management.Editor")] 13 | namespace UnityEngine.XR.Management 14 | { 15 | internal static class XRManagementAnalytics 16 | { 17 | private const int kMaxEventsPerHour = 1000; 18 | private const int kMaxNumberOfElements = 1000; 19 | private const string kVendorKey = "unity.xrmanagement"; 20 | private const string kEventBuild = "xrmanagment_build"; 21 | 22 | #if ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS 23 | private static bool s_Initialized = false; 24 | #endif //ENABLE_CLOUD_SERVICES_ANALYTICS && UNITY_ANALYTICS 25 | 26 | [Serializable] 27 | private struct BuildEvent 28 | { 29 | public string buildGuid; 30 | public string buildTarget; 31 | public string buildTargetGroup; 32 | public string[] assigned_loaders; 33 | } 34 | 35 | private static bool Initialize() 36 | { 37 | #if ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS 38 | return false; 39 | #else 40 | 41 | #if UNITY_EDITOR 42 | if (!EditorAnalytics.enabled) 43 | return false; 44 | 45 | if(AnalyticsResult.Ok != EditorAnalytics.RegisterEventWithLimit(kEventBuild, kMaxEventsPerHour, kMaxNumberOfElements, kVendorKey)) 46 | return false; 47 | s_Initialized = true; 48 | #endif //UNITY_EDITOR 49 | return s_Initialized; 50 | #endif //ENABLE_TEST_SUPPORT || !ENABLE_CLOUD_SERVICES_ANALYTICS || !UNITY_ANALYTICS 51 | 52 | } 53 | 54 | #if UNITY_EDITOR 55 | public static void SendBuildEvent(GUID guid, BuildTarget buildTarget, BuildTargetGroup buildTargetGroup, IEnumerable loaders) 56 | { 57 | 58 | #if UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS 59 | 60 | if (!s_Initialized && !Initialize()) 61 | { 62 | return; 63 | } 64 | 65 | List loaderTypeNames = new List(); 66 | foreach (var loader in loaders) 67 | { 68 | loaderTypeNames.Add(loader.GetType().Name); 69 | } 70 | 71 | var data = new BuildEvent 72 | { 73 | buildGuid = guid.ToString(), 74 | buildTarget = buildTarget.ToString(), 75 | buildTargetGroup = buildTargetGroup.ToString(), 76 | assigned_loaders = loaderTypeNames.ToArray(), 77 | }; 78 | 79 | EditorAnalytics.SendEventWithLimit(kEventBuild, data); 80 | 81 | #endif //UNITY_ANALYTICS && ENABLE_CLOUD_SERVICES_ANALYTICS 82 | 83 | } 84 | #endif //UNITY_EDITOR 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_TrackingReferenceManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace Valve.VR 5 | { 6 | public class SteamVR_TrackingReferenceManager : MonoBehaviour 7 | { 8 | static SteamVR_TrackingReferenceManager() 9 | { 10 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 11 | } 12 | 13 | private Dictionary trackingReferences = new Dictionary(); 14 | 15 | private void OnEnable() 16 | { 17 | SteamVR_Events.NewPoses.Listen(OnNewPoses); 18 | } 19 | 20 | private void OnDisable() 21 | { 22 | SteamVR_Events.NewPoses.Remove(OnNewPoses); 23 | } 24 | 25 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 26 | private void OnNewPoses(TrackedDevicePose_t[] poses) 27 | { 28 | if (poses == null) 29 | return; 30 | 31 | for (uint deviceIndex = 0; deviceIndex < poses.Length; deviceIndex++) 32 | { 33 | if (trackingReferences.ContainsKey(deviceIndex) == false) 34 | { 35 | ETrackedDeviceClass deviceClass = OpenVR.System.GetTrackedDeviceClass(deviceIndex); 36 | 37 | if (deviceClass == ETrackedDeviceClass.TrackingReference) 38 | { 39 | TrackingReferenceObject trackingReference = new TrackingReferenceObject(); 40 | trackingReference.trackedDeviceClass = deviceClass; 41 | trackingReference.gameObject = new GameObject("Tracking Reference " + deviceIndex.ToString()); 42 | trackingReference.gameObject.transform.parent = this.transform; 43 | trackingReference.trackedObject = trackingReference.gameObject.AddComponent(); 44 | trackingReference.renderModel = trackingReference.gameObject.AddComponent(); 45 | trackingReference.renderModel.createComponents = false; 46 | trackingReference.renderModel.updateDynamically = false; 47 | 48 | trackingReferences.Add(deviceIndex, trackingReference); 49 | 50 | trackingReference.gameObject.SendMessage("SetDeviceIndex", (int)deviceIndex, SendMessageOptions.DontRequireReceiver); 51 | } 52 | else 53 | { 54 | trackingReferences.Add(deviceIndex, new TrackingReferenceObject() { trackedDeviceClass = deviceClass }); 55 | } 56 | } 57 | } 58 | } 59 | 60 | private class TrackingReferenceObject 61 | { 62 | public ETrackedDeviceClass trackedDeviceClass; 63 | public GameObject gameObject; 64 | public SteamVR_RenderModel renderModel; 65 | public SteamVR_TrackedObject trackedObject; 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [日本語](README.ja.md) 2 | 3 | # VR Trial plugin for Honey Come 4 | This is an experimental project for a VR plugin for Honey Come. 5 | 6 | It is incomplete and faces many challenges, yet it offers a glimpse into the potential of Honey Come VR. 7 | 8 | If you believe you can contribute, let's tackle these challenges together. 9 | 10 | Then, embark on the journey to build your own customized VR plugin. 11 | 12 | ---- 13 | 14 | ## Prerequisites 15 | - Honey Come 16 | - Latest version of [BepInEx 6.x Unity IL2CPP for Windows (x64) games](https://builds.bepinex.dev/projects/bepinex_be) 17 | - An HMD (I'm using Meta Quest 2, but essentially any HMD should work provided that SteamVR recognizes it) 18 | - SteamVR 19 | - [BepisPlugins](https://github.com/IllusionMods/BepisPlugins/) 20 | - [BepInEx.ConfigurationManager](https://github.com/BepInEx/BepInEx.ConfigurationManager) 21 | - No other VR plugins installed 22 | 23 | ---- 24 | 25 | ## How to play 26 | To play, install [HC_VRTrial](https://github.com/toydev/HC_VRTrial/releases) into the game, then connect your HMD to SteamVR and launch the game. 27 | 28 | The plugin will automatically activate upon detecting SteamVR's process at startup. 29 | 30 | ---- 31 | 32 | ## Operations 33 | Double-click the right mouse button to update the viewport according to the direction of the head. 34 | 35 | For all other controls, please use the keyboard and mouse as you would in normal gameplay. 36 | 37 | ---- 38 | 39 | ## Configuration 40 | ### VRExperienceOptimization section 41 | |Key|default|description| 42 | |----|----|----| 43 | |DisableLights|true|If true, disables all lights.| 44 | |DisableLODGroups|true|If true, disables all LODGroups.| 45 | |DisableParticleSystems|true|If true, enables the conditional disabling of ParticleSystems based on the ParticleNameDisableRegex setting.| 46 | |ParticleNameDisableRegex|(?!Star\|Heart\|ef_ne)|Regex pattern to specify which ParticleSystems should be disabled. Requires DisableParticleSystems to be true. Only ParticleSystems matching this pattern will be affected.| 47 | 48 | ### Viewport section 49 | |Key|default|description| 50 | |----|----|----| 51 | |DoubleClickIntervalToUpdateViewport|0.2f|Defines the maximum interval, in seconds, that is considered for detecting a double-click to update the viewport's orientation based on HMD rotation. Set to 0 or less to disable this feature.| 52 | |ReflectHMDRotationXOnViewport|true|Reflects the HMD's vertical orientation (X-axis rotation) on the viewport. Enable this for use while lying on your back or stomach.| 53 | |ReflectHMDRotationYOnViewport|true|Reflects the HMD's horizontal orientation (Y-axis rotation) on the viewport. It is commonly enabled for use.| 54 | |ReflectHMDRotationZOnViewport|true|Reflects the HMD's tilt (Z-axis rotation) on the viewport. Enable this for use while lying on your side.| 55 | 56 | Below are examples of settings for each playstyle, with `Supine/Prone` set as the default. 57 | 58 | |Style|ReflectHMDRotationXOnViewport
HMD's Vertical Orientation
(X-axis rotation)|ReflectHMDRotationYOnViewport
HMD's Horizontal Orientation
(Y-axis rotation)|ReflectHMDRotationZOnViewport
HMD's tilt
(Z-axis rotation)| 59 | |----|----|----|----| 60 | |Sitting/Standing|Disabled|Enabled|Disabled| 61 | |Supine/Prone (Default)|Enabled|Enabled|Enabled| 62 | |Lateral|Enabled|Enabled|Enabled| 63 | 64 | ---- 65 | 66 | ## For developers 67 | 68 | - [Developer wiki home](https://github.com/toydev/HC_VRTrial/wiki/Home) 69 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR_Input/ActionSetClasses/SteamVR_Input_ActionSet_default.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Valve.VR 12 | { 13 | public class SteamVR_Input_ActionSet_default : Valve.VR.SteamVR_ActionSet 14 | { 15 | 16 | public virtual SteamVR_Action_Boolean InteractUI 17 | { 18 | get 19 | { 20 | return SteamVR_Actions.default_InteractUI; 21 | } 22 | } 23 | 24 | public virtual SteamVR_Action_Boolean Teleport 25 | { 26 | get 27 | { 28 | return SteamVR_Actions.default_Teleport; 29 | } 30 | } 31 | 32 | public virtual SteamVR_Action_Boolean GrabPinch 33 | { 34 | get 35 | { 36 | return SteamVR_Actions.default_GrabPinch; 37 | } 38 | } 39 | 40 | public virtual SteamVR_Action_Boolean GrabGrip 41 | { 42 | get 43 | { 44 | return SteamVR_Actions.default_GrabGrip; 45 | } 46 | } 47 | 48 | public virtual SteamVR_Action_Pose Pose 49 | { 50 | get 51 | { 52 | return SteamVR_Actions.default_Pose; 53 | } 54 | } 55 | 56 | public virtual SteamVR_Action_Skeleton SkeletonLeftHand 57 | { 58 | get 59 | { 60 | return SteamVR_Actions.default_SkeletonLeftHand; 61 | } 62 | } 63 | 64 | public virtual SteamVR_Action_Skeleton SkeletonRightHand 65 | { 66 | get 67 | { 68 | return SteamVR_Actions.default_SkeletonRightHand; 69 | } 70 | } 71 | 72 | public virtual SteamVR_Action_Single Squeeze 73 | { 74 | get 75 | { 76 | return SteamVR_Actions.default_Squeeze; 77 | } 78 | } 79 | 80 | public virtual SteamVR_Action_Boolean HeadsetOnHead 81 | { 82 | get 83 | { 84 | return SteamVR_Actions.default_HeadsetOnHead; 85 | } 86 | } 87 | 88 | public virtual SteamVR_Action_Boolean SnapTurnLeft 89 | { 90 | get 91 | { 92 | return SteamVR_Actions.default_SnapTurnLeft; 93 | } 94 | } 95 | 96 | public virtual SteamVR_Action_Boolean SnapTurnRight 97 | { 98 | get 99 | { 100 | return SteamVR_Actions.default_SnapTurnRight; 101 | } 102 | } 103 | 104 | public virtual SteamVR_Action_Vibration Haptic 105 | { 106 | get 107 | { 108 | return SteamVR_Actions.default_Haptic; 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/OpenVRHelpers.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | namespace Unity.XR.OpenVR 4 | { 5 | public class OpenVRHelpers 6 | { 7 | public static bool IsUsingSteamVRInput() 8 | { 9 | return DoesTypeExist("SteamVR_Input"); 10 | } 11 | 12 | public static bool DoesTypeExist(string className, bool fullname = false) 13 | { 14 | return GetType(className, fullname) != null; 15 | } 16 | 17 | public static Type GetType(string className, bool fullname = false) 18 | { 19 | if (fullname) 20 | { 21 | try 22 | { 23 | foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) 24 | { 25 | try 26 | { 27 | foreach (var type in assembly.GetTypes()) 28 | { 29 | if (type.FullName == className) return type; 30 | } 31 | } 32 | catch (Exception) 33 | { 34 | // ignore 35 | } 36 | } 37 | } 38 | catch (Exception) 39 | { 40 | // ignore 41 | } 42 | return null; 43 | } 44 | else 45 | { 46 | try 47 | { 48 | foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) 49 | { 50 | try 51 | { 52 | foreach (var type in assembly.GetTypes()) 53 | { 54 | if (type.Name == className) return type; 55 | } 56 | } 57 | catch (Exception) 58 | { 59 | // ignore 60 | } 61 | } 62 | } 63 | catch (Exception) 64 | { 65 | // ignore 66 | } 67 | return null; 68 | } 69 | } 70 | 71 | public static string GetActionManifestPathFromPlugin() 72 | { 73 | Type steamvrInputType = GetType("SteamVR_Input"); 74 | MethodInfo getPathMethod = steamvrInputType.GetMethod("GetActionsFilePath"); 75 | object path = getPathMethod.Invoke(null, new object[] { false }); 76 | 77 | return (string)path; 78 | } 79 | 80 | public static string GetActionManifestNameFromPlugin() 81 | { 82 | Type steamvrInputType = GetType("SteamVR_Input"); 83 | MethodInfo getPathMethod = steamvrInputType.GetMethod("GetActionsFileName"); 84 | object path = getPathMethod.Invoke(null, null); 85 | 86 | return (string)path; 87 | } 88 | 89 | public static string GetEditorAppKeyFromPlugin() 90 | { 91 | Type steamvrInputType = GetType("SteamVR_Input"); 92 | MethodInfo getPathMethod = steamvrInputType.GetMethod("GetEditorAppKey"); 93 | object path = getPathMethod.Invoke(null, null); 94 | 95 | return (string)path; 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/IMGUICapture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | using HC_VRTrial.Logging; 4 | using Il2CppInterop.Runtime.Injection; 5 | using Il2CppInterop.Runtime.Attributes; 6 | 7 | namespace HC_VRTrial.VRUtils 8 | { 9 | /// 10 | /// This class captures IMGUI elements and displays them on a RenderTexture. 11 | /// 12 | public class IMGUICapture : MonoBehaviour 13 | { 14 | static IMGUICapture() { ClassInjector.RegisterTypeInIl2Cpp(); } 15 | 16 | [HideFromIl2Cpp] 17 | public static IMGUICapture Create(GameObject parentGameObject, string name) 18 | { 19 | var gameObject = new GameObject($"{parentGameObject.name}{name}"); 20 | // Ensure the lifecycle of the GameObject is synchronized with its parent. 21 | gameObject.SetActive(false); 22 | var result = gameObject.AddComponent(); 23 | gameObject.AddComponent(); 24 | gameObject.AddComponent(); 25 | gameObject.SetActive(true); 26 | return result; 27 | } 28 | 29 | [HideFromIl2Cpp] 30 | public RenderTexture LastTexture { get; private set; } 31 | [HideFromIl2Cpp] 32 | public RenderTexture Texture { get; private set; } 33 | 34 | void Awake() 35 | { 36 | PluginLog.Debug($"Awake: {name}"); 37 | 38 | Texture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32); 39 | } 40 | 41 | void OnDestroy() 42 | { 43 | PluginLog.Debug($"OnDestroy: {name}"); 44 | 45 | if (Texture != null) 46 | { 47 | Texture.Release(); 48 | Texture = null; 49 | } 50 | } 51 | 52 | /// 53 | /// Captures the GUI elements by setting the RenderTexture at the beginning of the GUI rendering process. 54 | /// 55 | private class FirstGUIEventProcessor : MonoBehaviour 56 | { 57 | static FirstGUIEventProcessor() { ClassInjector.RegisterTypeInIl2Cpp(); } 58 | 59 | void OnGUI() 60 | { 61 | GUI.depth = int.MaxValue; 62 | if (Event.current.type == EventType.Repaint) 63 | { 64 | var capture = GetComponent(); 65 | if (capture) 66 | { 67 | capture.LastTexture = RenderTexture.active; 68 | RenderTexture.active = capture.Texture; 69 | GL.Clear(true, true, Color.clear); 70 | } 71 | } 72 | } 73 | } 74 | 75 | /// 76 | /// Restores the original RenderTexture after capturing the GUI elements. 77 | /// 78 | private class LastGUIEventProcessor : MonoBehaviour 79 | { 80 | static LastGUIEventProcessor() { ClassInjector.RegisterTypeInIl2Cpp(); } 81 | 82 | void OnGUI() 83 | { 84 | GUI.depth = int.MinValue; 85 | if (Event.current.type == EventType.Repaint) 86 | { 87 | var capture = GetComponent(); 88 | if (capture) RenderTexture.active = capture.LastTexture; 89 | } 90 | } 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_TrackedObject.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: For controlling in-game objects with tracked devices. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | public class SteamVR_TrackedObject : MonoBehaviour 12 | { 13 | static SteamVR_TrackedObject() 14 | { 15 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 16 | } 17 | 18 | public enum EIndex 19 | { 20 | None = -1, 21 | Hmd = (int)OpenVR.k_unTrackedDeviceIndex_Hmd, 22 | Device1, 23 | Device2, 24 | Device3, 25 | Device4, 26 | Device5, 27 | Device6, 28 | Device7, 29 | Device8, 30 | Device9, 31 | Device10, 32 | Device11, 33 | Device12, 34 | Device13, 35 | Device14, 36 | Device15, 37 | Device16 38 | } 39 | 40 | public EIndex index; 41 | 42 | // [Tooltip("If not set, relative to parent")] 43 | public Transform origin; 44 | 45 | public bool isValid { get; private set; } 46 | 47 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 48 | private void OnNewPoses(TrackedDevicePose_t[] poses) 49 | { 50 | if (index == EIndex.None) 51 | return; 52 | 53 | var i = (int)index; 54 | 55 | isValid = false; 56 | if (poses.Length <= i) 57 | return; 58 | 59 | if (!poses[i].bDeviceIsConnected) 60 | return; 61 | 62 | if (!poses[i].bPoseIsValid) 63 | return; 64 | 65 | isValid = true; 66 | 67 | var pose = new SteamVR_Utils.RigidTransform(poses[i].mDeviceToAbsoluteTracking); 68 | 69 | if (origin != null) 70 | { 71 | transform.position = origin.transform.TransformPoint(pose.pos); 72 | transform.rotation = origin.rotation * pose.rot; 73 | } 74 | else 75 | { 76 | transform.localPosition = pose.pos; 77 | transform.localRotation = pose.rot; 78 | } 79 | } 80 | 81 | SteamVR_Events.Action newPosesAction; 82 | 83 | SteamVR_TrackedObject() 84 | { 85 | newPosesAction = SteamVR_Events.NewPosesAction(OnNewPoses); 86 | } 87 | 88 | private void Awake() 89 | { 90 | OnEnable(); 91 | } 92 | 93 | void OnEnable() 94 | { 95 | var render = SteamVR_Render.instance; 96 | if (render == null) 97 | { 98 | enabled = false; 99 | return; 100 | } 101 | 102 | newPosesAction.enabled = true; 103 | } 104 | 105 | void OnDisable() 106 | { 107 | newPosesAction.enabled = false; 108 | isValid = false; 109 | } 110 | 111 | public void SetDeviceIndex(int index) 112 | { 113 | if (System.Enum.IsDefined(typeof(EIndex), index)) 114 | this.index = (EIndex)index; 115 | } 116 | } 117 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Input_Source.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | using System; 5 | using System.ComponentModel; 6 | using System.Collections.Generic; 7 | 8 | namespace Valve.VR 9 | { 10 | public static class SteamVR_Input_Source 11 | { 12 | public static int numSources = System.Enum.GetValues(typeof(SteamVR_Input_Sources)).Length; 13 | 14 | private static ulong[] inputSourceHandlesBySource; 15 | private static Dictionary inputSourceSourcesByHandle = new Dictionary(); 16 | 17 | private static Type enumType = typeof(SteamVR_Input_Sources); 18 | private static Type descriptionType = typeof(DescriptionAttribute); 19 | 20 | private static SteamVR_Input_Sources[] allSources; 21 | 22 | public static ulong GetHandle(SteamVR_Input_Sources inputSource) 23 | { 24 | int index = (int)inputSource; 25 | if (index < inputSourceHandlesBySource.Length) 26 | return inputSourceHandlesBySource[index]; 27 | 28 | return 0; 29 | } 30 | public static SteamVR_Input_Sources GetSource(ulong handle) 31 | { 32 | if (inputSourceSourcesByHandle.ContainsKey(handle)) 33 | return inputSourceSourcesByHandle[handle]; 34 | 35 | return SteamVR_Input_Sources.Any; 36 | } 37 | 38 | public static SteamVR_Input_Sources[] GetAllSources() 39 | { 40 | if (allSources == null) 41 | allSources = (SteamVR_Input_Sources[])System.Enum.GetValues(typeof(SteamVR_Input_Sources)); 42 | 43 | return allSources; 44 | } 45 | 46 | private static string GetPath(string inputSourceEnumName) 47 | { 48 | return ((DescriptionAttribute)enumType.GetMember(inputSourceEnumName)[0].GetCustomAttributes(descriptionType, false)[0]).Description; 49 | } 50 | 51 | public static void Initialize() 52 | { 53 | List allSourcesList = new List(); 54 | string[] enumNames = System.Enum.GetNames(enumType); 55 | inputSourceHandlesBySource = new ulong[enumNames.Length]; 56 | inputSourceSourcesByHandle = new Dictionary(); 57 | 58 | for (int enumIndex = 0; enumIndex < enumNames.Length; enumIndex++) 59 | { 60 | string path = GetPath(enumNames[enumIndex]); 61 | 62 | ulong handle = 0; 63 | EVRInputError err = OpenVR.Input.GetInputSourceHandle(path, ref handle); 64 | 65 | if (err != EVRInputError.None) 66 | Debug.LogError("[SteamVR] GetInputSourceHandle (" + path + ") error: " + err.ToString()); 67 | 68 | if (enumNames[enumIndex] == SteamVR_Input_Sources.Any.ToString()) //todo: temporary hack 69 | { 70 | inputSourceHandlesBySource[enumIndex] = 0; 71 | inputSourceSourcesByHandle.Add(0, (SteamVR_Input_Sources)enumIndex); 72 | } 73 | else 74 | { 75 | inputSourceHandlesBySource[enumIndex] = handle; 76 | inputSourceSourcesByHandle.Add(handle, (SteamVR_Input_Sources)enumIndex); 77 | } 78 | 79 | allSourcesList.Add((SteamVR_Input_Sources)enumIndex); 80 | } 81 | 82 | allSources = allSourcesList.ToArray(); 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/XRLoader.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine.Rendering; 3 | 4 | namespace UnityEngine.XR.Management 5 | { 6 | /// 7 | /// XR Loader abstract class used as a base class for specific provider implementations. Providers should implement 8 | /// subclasses of this to provide specific initialization and management implementations that make sense for their supported 9 | /// scenarios and needs. 10 | /// 11 | public abstract class XRLoader : ScriptableObject 12 | { 13 | /// 14 | /// Initialize the loader. This should initialize all subsystems to support the desired runtime setup this 15 | /// loader represents. 16 | /// 17 | /// This is the only method on XRLoader that Management uses to determine the active loader to use. If this 18 | /// method returns true, Management locks this loader as the 19 | /// and and stops fall through processing on the list of current loaders. 20 | /// 21 | /// If this method returns false, continues to process the next loader 22 | /// in the list, or fails completely when the list is exhausted. 23 | /// 24 | /// 25 | /// Whether or not initialization succeeded. 26 | public virtual bool Initialize() { return true; } 27 | 28 | /// 29 | /// Ask loader to start all initialized subsystems. 30 | /// 31 | /// 32 | /// Whether or not all subsystems were successfully started. 33 | public virtual bool Start() { return true; } 34 | 35 | /// 36 | /// Ask loader to stop all initialized subsystems. 37 | /// 38 | /// 39 | /// Whether or not all subsystems were successfully stopped. 40 | public virtual bool Stop() { return true; } 41 | 42 | /// 43 | /// Ask loader to deinitialize all initialized subsystems. 44 | /// 45 | /// 46 | /// Whether or not deinitialization succeeded. 47 | public virtual bool Deinitialize() { return true; } 48 | 49 | /// 50 | /// Gets the loaded subsystem of the specified type. Implementation dependent as only implemetnations 51 | /// know what they have loaded and how best to get it.. 52 | /// 53 | /// 54 | /// Type of the subsystem to get 55 | /// 56 | /// The loaded subsystem or null if not found. 57 | public virtual IntegratedSubsystem GetLoadedIntegratedSubsystem(string id) { return null; } 58 | 59 | /// 60 | /// Gets the loader's supported graphics device types. If the list is empty, it is assumed that it supports all graphics device types. 61 | /// 62 | /// 63 | /// True if the player is being built. You may want to include or exclude graphics apis if the player is being built or not. 64 | /// Returns the loader's supported graphics device types. 65 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 66 | public virtual List GetSupportedGraphicsDeviceTypes(bool buildingPlayer) 67 | { 68 | return new List(); 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/VR.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | using BepInEx.Unity.IL2CPP.Utils; 5 | using Il2CppInterop.Runtime.Attributes; 6 | using Il2CppInterop.Runtime.Injection; 7 | using Unity.XR.OpenVR; 8 | using UnityEngine; 9 | using Valve.VR; 10 | 11 | using HC_VRTrial.Logging; 12 | 13 | namespace HC_VRTrial.VRUtils 14 | { 15 | public class VR : MonoBehaviour 16 | { 17 | static VR() { ClassInjector.RegisterTypeInIl2Cpp(); } 18 | 19 | public static bool Initialized { get; private set; } = false; 20 | 21 | public static void Initialize(Action actionAfterInitialization, bool force = false) 22 | { 23 | if (force || !Initialized) 24 | { 25 | Initialized = false; 26 | ActionAfterInitialization = actionAfterInitialization; 27 | new GameObject(nameof(VR)) { hideFlags = HideFlags.HideAndDontSave }.AddComponent(); 28 | } 29 | } 30 | 31 | private static Action ActionAfterInitialization { get; set; } 32 | 33 | void Start() 34 | { 35 | this.StartCoroutine(Setup()); 36 | } 37 | 38 | [HideFromIl2Cpp] 39 | private IEnumerator Setup() 40 | { 41 | PluginLog.Info("Start Setup"); 42 | 43 | try 44 | { 45 | try 46 | { 47 | // Initialize the OpenVR Display and OpenVR Input submodules. 48 | var vrLoader = ScriptableObject.CreateInstance(); 49 | if (vrLoader.Initialize()) 50 | { 51 | PluginLog.Info("OpenVRLoader.Initialize succeeded."); 52 | } 53 | else 54 | { 55 | PluginLog.Error("OpenVRLoader.Initialize failed."); 56 | yield break; 57 | } 58 | 59 | // Start the OpenVR Display and OpenVR Input submodules. 60 | if (vrLoader.Start()) 61 | { 62 | PluginLog.Info("OpenVRLoader.Start succeeded."); 63 | } 64 | else 65 | { 66 | PluginLog.Error("OpenVRLoader.Start failed."); 67 | yield break; 68 | } 69 | 70 | // Initialize SteamVR. 71 | SteamVR_Behaviour.Initialize(false); 72 | } 73 | catch (Exception e) 74 | { 75 | throw new Exception("SteamVR initialization error.", e); 76 | } 77 | 78 | // Wait for initialization. 79 | while (true) 80 | { 81 | switch (SteamVR.initializedState) 82 | { 83 | case SteamVR.InitializedStates.InitializeSuccess: 84 | PluginLog.Info("SteamVR initialization succeeded."); 85 | break; 86 | case SteamVR.InitializedStates.InitializeFailure: 87 | PluginLog.Error("SteamVR initialization failed."); 88 | yield break; 89 | default: 90 | yield return new WaitForSeconds(0.1f); 91 | continue; 92 | } 93 | 94 | break; 95 | } 96 | 97 | Initialized = true; 98 | ActionAfterInitialization?.Invoke(); 99 | } 100 | finally 101 | { 102 | PluginLog.Info("Finish Setup"); 103 | Destroy(gameObject); 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/UGUICapture.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | using UnityEngine.UI.Collections; 6 | 7 | using HC_VRTrial.Logging; 8 | using Il2CppInterop.Runtime.Injection; 9 | using Il2CppInterop.Runtime.Attributes; 10 | 11 | namespace HC_VRTrial.VRUtils 12 | { 13 | /// 14 | /// This class captures uGUI elements and displays them on a RenderTexture. 15 | /// 16 | public class UGUICapture : MonoBehaviour 17 | { 18 | static UGUICapture() { ClassInjector.RegisterTypeInIl2Cpp(); } 19 | 20 | /// 21 | /// Creates and initializes a UGUICapture instance. 22 | /// 23 | /// Parent game object. 24 | /// Name. 25 | /// Working layer occupied for capture. 26 | /// A new instance of UGUICapture. 27 | [HideFromIl2Cpp] 28 | public static UGUICapture Create(GameObject parentGameObject, string name, int layer) 29 | { 30 | var gameObject = new GameObject($"{parentGameObject.name}{name}"); 31 | // Ensure the lifecycle of the GameObject is synchronized with its parent. 32 | gameObject.transform.parent = parentGameObject.transform; 33 | gameObject.SetActive(false); 34 | var result = gameObject.AddComponent(); 35 | result.Layer = layer; 36 | gameObject.SetActive(true); 37 | return result; 38 | } 39 | 40 | private int Layer { get; set; } 41 | public RenderTexture Texture { get; private set; } 42 | private Il2CppSystem.Collections.Generic.Dictionary> CanvasGraphics { get; set; } 43 | [HideFromIl2Cpp] 44 | private ISet ProcessedCanvas { get; set; } = new HashSet(); 45 | 46 | void Awake() 47 | { 48 | PluginLog.Debug($"Awake: {name}"); 49 | 50 | Texture = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32); 51 | 52 | // Creates a camera to project the captured uGUI elements onto the RenderTexture. 53 | var camera = gameObject.AddComponent(); 54 | camera.cullingMask = 1 << Layer; 55 | camera.depth = float.MaxValue; 56 | camera.nearClipPlane = -1000f; 57 | camera.farClipPlane = 1000f; 58 | camera.targetTexture = Texture; 59 | camera.backgroundColor = Color.clear; 60 | camera.clearFlags = CameraClearFlags.Color; 61 | camera.orthographic = true; 62 | camera.useOcclusionCulling = false; 63 | CanvasGraphics = GraphicRegistry.instance.m_Graphics; 64 | } 65 | 66 | void OnDestroy() 67 | { 68 | PluginLog.Debug($"OnDestroy: {name}"); 69 | 70 | if (Texture != null) 71 | { 72 | Texture.Release(); 73 | Texture = null; 74 | } 75 | } 76 | 77 | void Update() 78 | { 79 | // Redirects the uGUI canvas output to a pre-prepared RenderTexture for capturing. 80 | var camera = GetComponent(); 81 | foreach (var canvas in CanvasGraphics.Keys) 82 | { 83 | if (canvas.enabled && (!ProcessedCanvas.Contains(canvas) || canvas.renderMode != RenderMode.ScreenSpaceCamera || canvas.worldCamera != camera)) 84 | { 85 | PluginLog.Debug($"Add canvas to capture target: {canvas.name} in {canvas.gameObject.layer}:{LayerMask.LayerToName(canvas.gameObject.layer)}"); 86 | ProcessedCanvas.Add(canvas); 87 | canvas.renderMode = RenderMode.ScreenSpaceCamera; 88 | canvas.worldCamera = camera; 89 | foreach (var i in canvas.gameObject.GetComponentsInChildren()) i.gameObject.layer = Layer; 90 | } 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_Skybox.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Sets cubemap to use in the compositor. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | public class SteamVR_Skybox : MonoBehaviour 12 | { 13 | static SteamVR_Skybox() 14 | { 15 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 16 | } 17 | 18 | // Note: Unity's Left and Right Skybox shader variables are switched. 19 | public Texture front, back, left, right, top, bottom; 20 | 21 | public enum CellSize 22 | { 23 | x1024, x64, x32, x16, x8 24 | } 25 | public CellSize StereoCellSize = CellSize.x32; 26 | 27 | public float StereoIpdMm = 64.0f; 28 | 29 | public void SetTextureByIndex(int i, Texture t) 30 | { 31 | switch (i) 32 | { 33 | case 0: 34 | front = t; 35 | break; 36 | case 1: 37 | back = t; 38 | break; 39 | case 2: 40 | left = t; 41 | break; 42 | case 3: 43 | right = t; 44 | break; 45 | case 4: 46 | top = t; 47 | break; 48 | case 5: 49 | bottom = t; 50 | break; 51 | } 52 | } 53 | 54 | public Texture GetTextureByIndex(int i) 55 | { 56 | switch (i) 57 | { 58 | case 0: 59 | return front; 60 | case 1: 61 | return back; 62 | case 2: 63 | return left; 64 | case 3: 65 | return right; 66 | case 4: 67 | return top; 68 | case 5: 69 | return bottom; 70 | } 71 | return null; 72 | } 73 | 74 | static public void SetOverride( 75 | Texture front = null, 76 | Texture back = null, 77 | Texture left = null, 78 | Texture right = null, 79 | Texture top = null, 80 | Texture bottom = null) 81 | { 82 | var compositor = OpenVR.Compositor; 83 | if (compositor != null) 84 | { 85 | var handles = new Texture[] { front, back, left, right, top, bottom }; 86 | var textures = new Texture_t[6]; 87 | for (int i = 0; i < 6; i++) 88 | { 89 | textures[i].handle = (handles[i] != null) ? handles[i].GetNativeTexturePtr() : System.IntPtr.Zero; 90 | textures[i].eType = SteamVR.instance.textureType; 91 | textures[i].eColorSpace = EColorSpace.Auto; 92 | } 93 | var error = compositor.SetSkyboxOverride(textures); 94 | if (error != EVRCompositorError.None) 95 | { 96 | Debug.LogError("[SteamVR] Failed to set skybox override with error: " + error); 97 | if (error == EVRCompositorError.TextureIsOnWrongDevice) 98 | Debug.Log("[SteamVR] Set your graphics driver to use the same video card as the headset is plugged into for Unity."); 99 | else if (error == EVRCompositorError.TextureUsesUnsupportedFormat) 100 | Debug.Log("[SteamVR] Ensure skybox textures are not compressed and have no mipmaps."); 101 | } 102 | } 103 | } 104 | 105 | static public void ClearOverride() 106 | { 107 | var compositor = OpenVR.Compositor; 108 | if (compositor != null) 109 | compositor.ClearSkyboxOverride(); 110 | } 111 | 112 | void OnEnable() 113 | { 114 | SetOverride(front, back, left, right, top, bottom); 115 | } 116 | 117 | void OnDisable() 118 | { 119 | ClearOverride(); 120 | } 121 | } 122 | } -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/CameraHijacker.cs: -------------------------------------------------------------------------------- 1 | using Il2CppInterop.Runtime.Injection; 2 | using Il2CppInterop.Runtime.Attributes; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | 6 | using HC_VRTrial.Logging; 7 | 8 | namespace HC_VRTrial.VRUtils 9 | { 10 | /// 11 | /// Hijack the camera's view to another camera. 12 | /// To minimize the impact, the original camera remains enabled and is virtually disabled by adjusting CullingMask before and after drawing. 13 | /// 14 | public class CameraHijacker : MonoBehaviour 15 | { 16 | static CameraHijacker() { ClassInjector.RegisterTypeInIl2Cpp(); } 17 | 18 | /// 19 | /// Hijack the camera's view to another camera. 20 | /// 21 | /// The source camera. 22 | /// The destination camera. If null, the function only disables the source camera without redirecting its view. 23 | /// If true, copies the camera settings using Camera.CopyFrom. 24 | /// If true, synchronizes some of the camera settings in real-time. Refer to CameraHijacker.Synchronize for detailed synchronization content. 25 | [HideFromIl2Cpp] 26 | public static void Hijack(Camera source, Camera destination = null, bool useCopyFrom = true, bool synchronization = true) 27 | { 28 | if (source != null) 29 | { 30 | PluginLog.Debug(destination ? $"Hijack {source.name} to {destination?.name}" : $"Hijack {source.name}"); 31 | if (destination && useCopyFrom) destination.CopyFrom(source); 32 | var hijacker = source.GetComponent(); 33 | if (hijacker == null) hijacker = source.gameObject.AddComponent(); 34 | if (destination && synchronization) hijacker.Destination = destination; 35 | } 36 | } 37 | 38 | private Camera Destination { get; set; } 39 | private LayerMask LastCullingMask { get; set; } 40 | private CameraClearFlags LastClearFlags { get; set; } 41 | 42 | void Awake() 43 | { 44 | onBeginContextRendering = (Il2CppSystem.Action>)OnBeginContextRendering; 45 | onEndContextRendering = (Il2CppSystem.Action>)OnEndContextRendering; 46 | } 47 | 48 | void OnEnable() 49 | { 50 | RenderPipelineManager.beginContextRendering += onBeginContextRendering; 51 | RenderPipelineManager.endContextRendering += onEndContextRendering; 52 | } 53 | 54 | /// 55 | void OnDisable() 56 | { 57 | RenderPipelineManager.beginContextRendering -= onBeginContextRendering; 58 | RenderPipelineManager.endContextRendering -= onEndContextRendering; 59 | } 60 | 61 | private Il2CppSystem.Action> onBeginContextRendering; 62 | [HideFromIl2Cpp] 63 | void OnBeginContextRendering(ScriptableRenderContext context, Il2CppSystem.Collections.Generic.List cameras) 64 | { 65 | var camera = GetComponent(); 66 | if (camera != null) 67 | { 68 | LastCullingMask = camera.cullingMask; 69 | LastClearFlags = camera.clearFlags; 70 | camera.cullingMask = 0; 71 | camera.clearFlags = CameraClearFlags.Nothing; 72 | if (Destination != null) Synchronize(); 73 | } 74 | } 75 | 76 | private Il2CppSystem.Action> onEndContextRendering; 77 | [HideFromIl2Cpp] 78 | void OnEndContextRendering(ScriptableRenderContext context, Il2CppSystem.Collections.Generic.List cameras) 79 | { 80 | var camera = GetComponent(); 81 | if (camera != null) 82 | { 83 | camera.cullingMask = LastCullingMask; 84 | camera.clearFlags = LastClearFlags; 85 | } 86 | } 87 | 88 | private void Synchronize() 89 | { 90 | Destination.cullingMask = LastCullingMask; 91 | Destination.clearFlags = LastClearFlags; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_Fade.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: CameraFade script adapted to work with SteamVR. 4 | // 5 | // Usage: Add to your top level SteamVR_Camera (the one with ApplyDistoration 6 | // checked) and drag a reference to this component into SteamVR_Camera 7 | // RenderComponents list. Then call the static helper function 8 | // SteamVR_Fade.Start with the desired color and duration. 9 | // Use a duration of zero to set the start color. 10 | // 11 | // Example: Fade down from black over one second. 12 | // SteamVR_Fade.Start(Color.black, 0); 13 | // SteamVR_Fade.Start(Color.clear, 1); 14 | // 15 | // Note: This component is provided to fade out a single camera layer's 16 | // scene view. If instead you want to fade the entire view, use: 17 | // SteamVR_Fade.View(Color.black, 1); 18 | // (Does not affect the game view, however.) 19 | // 20 | //============================================================================= 21 | 22 | using UnityEngine; 23 | 24 | namespace Valve.VR 25 | { 26 | public class SteamVR_Fade : MonoBehaviour 27 | { 28 | static SteamVR_Fade() 29 | { 30 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 31 | } 32 | 33 | private Color currentColor = new Color(0, 0, 0, 0); // default starting color: black and fully transparent 34 | private Color targetColor = new Color(0, 0, 0, 0); // default target color: black and fully transparent 35 | private Color deltaColor = new Color(0, 0, 0, 0); // the delta-color is basically the "speed / second" at which the current color should change 36 | private bool fadeOverlay = false; 37 | 38 | static public void Start(Color newColor, float duration, bool fadeOverlay = false) 39 | { 40 | SteamVR_Events.Fade.Send(newColor, duration, fadeOverlay); 41 | } 42 | 43 | static public void View(Color newColor, float duration) 44 | { 45 | var compositor = OpenVR.Compositor; 46 | if (compositor != null) 47 | compositor.FadeToColor(duration, newColor.r, newColor.g, newColor.b, newColor.a, false); 48 | } 49 | 50 | #if TEST_FADE_VIEW 51 | void Update() 52 | { 53 | if (Input.GetKeyDown(KeyCode.Space)) 54 | { 55 | SteamVR_Fade.View(Color.black, 0); 56 | SteamVR_Fade.View(Color.clear, 1); 57 | } 58 | } 59 | #endif 60 | 61 | public void OnStartFade(Color newColor, float duration, bool fadeOverlay) 62 | { 63 | if (duration > 0.0f) 64 | { 65 | targetColor = newColor; 66 | deltaColor = (targetColor - currentColor) / duration; 67 | } 68 | else 69 | { 70 | currentColor = newColor; 71 | } 72 | } 73 | 74 | static Material fadeMaterial = null; 75 | static int fadeMaterialColorID = -1; 76 | 77 | void OnEnable() 78 | { 79 | if (fadeMaterial == null) 80 | { 81 | fadeMaterial = new Material(Shader.Find("Custom/SteamVR_Fade")); 82 | fadeMaterialColorID = Shader.PropertyToID("fadeColor"); 83 | } 84 | 85 | SteamVR_Events.Fade.Listen(OnStartFade); 86 | SteamVR_Events.FadeReady.Send(); 87 | } 88 | 89 | void OnDisable() 90 | { 91 | SteamVR_Events.Fade.Remove(OnStartFade); 92 | } 93 | 94 | void OnPostRender() 95 | { 96 | if (currentColor != targetColor) 97 | { 98 | // if the difference between the current alpha and the desired alpha is smaller than delta-alpha * deltaTime, then we're pretty much done fading: 99 | if (Mathf.Abs(currentColor.a - targetColor.a) < Mathf.Abs(deltaColor.a) * Time.deltaTime) 100 | { 101 | currentColor = targetColor; 102 | deltaColor = new Color(0, 0, 0, 0); 103 | } 104 | else 105 | { 106 | currentColor += deltaColor * Time.deltaTime; 107 | } 108 | 109 | if (fadeOverlay) 110 | { 111 | var overlay = SteamVR_Overlay.instance; 112 | if (overlay != null) 113 | { 114 | overlay.alpha = 1.0f - currentColor.a; 115 | } 116 | } 117 | } 118 | 119 | if (currentColor.a > 0 && fadeMaterial) 120 | { 121 | fadeMaterial.SetColor(fadeMaterialColorID, currentColor); 122 | fadeMaterial.SetPass(0); 123 | GL.Begin(4 /*GL.QUADS*/); 124 | 125 | GL.Vertex3(-1, -1, 0); 126 | GL.Vertex3(1, -1, 0); 127 | GL.Vertex3(1, 1, 0); 128 | GL.Vertex3(-1, 1, 0); 129 | GL.End(); 130 | } 131 | } 132 | } 133 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/StreamingAssets/SteamVR/actions.json: -------------------------------------------------------------------------------- 1 | { 2 | "actions": [ 3 | { 4 | "name": "/actions/default/in/InteractUI", 5 | "type": "boolean" 6 | }, 7 | { 8 | "name": "/actions/default/in/Teleport", 9 | "type": "boolean" 10 | }, 11 | { 12 | "name": "/actions/default/in/GrabPinch", 13 | "type": "boolean" 14 | }, 15 | { 16 | "name": "/actions/default/in/GrabGrip", 17 | "type": "boolean" 18 | }, 19 | { 20 | "name": "/actions/default/in/Pose", 21 | "type": "pose" 22 | }, 23 | { 24 | "name": "/actions/default/in/SkeletonLeftHand", 25 | "type": "skeleton", 26 | "skeleton": "/skeleton/hand/left" 27 | }, 28 | { 29 | "name": "/actions/default/in/SkeletonRightHand", 30 | "type": "skeleton", 31 | "skeleton": "/skeleton/hand/right" 32 | }, 33 | { 34 | "name": "/actions/default/in/Squeeze", 35 | "type": "vector1", 36 | "requirement": "optional" 37 | }, 38 | { 39 | "name": "/actions/default/in/HeadsetOnHead", 40 | "type": "boolean", 41 | "requirement": "optional" 42 | }, 43 | { 44 | "name": "/actions/default/in/SnapTurnLeft", 45 | "type": "boolean", 46 | "requirement": "suggested" 47 | }, 48 | { 49 | "name": "/actions/default/in/SnapTurnRight", 50 | "type": "boolean" 51 | }, 52 | { 53 | "name": "/actions/default/out/Haptic", 54 | "type": "vibration" 55 | }, 56 | { 57 | "name": "/actions/platformer/in/Move", 58 | "type": "vector2" 59 | }, 60 | { 61 | "name": "/actions/platformer/in/Jump", 62 | "type": "boolean" 63 | }, 64 | { 65 | "name": "/actions/buggy/in/Steering", 66 | "type": "vector2" 67 | }, 68 | { 69 | "name": "/actions/buggy/in/Throttle", 70 | "type": "vector1" 71 | }, 72 | { 73 | "name": "/actions/buggy/in/Brake", 74 | "type": "boolean" 75 | }, 76 | { 77 | "name": "/actions/buggy/in/Reset", 78 | "type": "boolean" 79 | }, 80 | { 81 | "name": "/actions/mixedreality/in/ExternalCamera", 82 | "type": "pose", 83 | "requirement": "optional" 84 | } 85 | ], 86 | "action_sets": [ 87 | { 88 | "name": "/actions/default", 89 | "usage": "single" 90 | }, 91 | { 92 | "name": "/actions/platformer", 93 | "usage": "single" 94 | }, 95 | { 96 | "name": "/actions/buggy", 97 | "usage": "single" 98 | }, 99 | { 100 | "name": "/actions/mixedreality", 101 | "usage": "single" 102 | } 103 | ], 104 | "default_bindings": [ 105 | { 106 | "controller_type": "vive_controller", 107 | "binding_url": "bindings_vive_controller.json" 108 | }, 109 | { 110 | "controller_type": "oculus_touch", 111 | "binding_url": "bindings_oculus_touch.json" 112 | }, 113 | { 114 | "controller_type": "knuckles", 115 | "binding_url": "bindings_knuckles.json" 116 | }, 117 | { 118 | "controller_type": "holographic_controller", 119 | "binding_url": "bindings_holographic_controller.json" 120 | }, 121 | { 122 | "controller_type": "vive_cosmos_controller", 123 | "binding_url": "bindings_vive_cosmos_controller.json" 124 | }, 125 | { 126 | "controller_type": "logitech_stylus", 127 | "binding_url": "bindings_logitech_stylus.json" 128 | }, 129 | { 130 | "controller_type": "vive_cosmos", 131 | "binding_url": "binding_vive_cosmos.json" 132 | }, 133 | { 134 | "controller_type": "vive", 135 | "binding_url": "binding_vive.json" 136 | }, 137 | { 138 | "controller_type": "indexhmd", 139 | "binding_url": "binding_index_hmd.json" 140 | }, 141 | { 142 | "controller_type": "vive_pro", 143 | "binding_url": "binding_vive_pro.json" 144 | }, 145 | { 146 | "controller_type": "rift", 147 | "binding_url": "binding_rift.json" 148 | }, 149 | { 150 | "controller_type": "holographic_hmd", 151 | "binding_url": "binding_holographic_hmd.json" 152 | }, 153 | { 154 | "controller_type": "vive_tracker_camera", 155 | "binding_url": "binding_vive_tracker_camera.json" 156 | } 157 | ], 158 | "localization": [ 159 | { 160 | "language_tag": "en_US", 161 | "/actions/default/in/GrabGrip": "Grab Grip", 162 | "/actions/default/in/GrabPinch": "Grab Pinch", 163 | "/actions/default/in/HeadsetOnHead": "Headset on head (proximity sensor)", 164 | "/actions/default/in/InteractUI": "Interact With UI", 165 | "/actions/default/in/Pose": "Pose", 166 | "/actions/default/in/SkeletonLeftHand": "Skeleton (Left)", 167 | "/actions/default/in/SkeletonRightHand": "Skeleton (Right)", 168 | "/actions/default/in/Teleport": "Teleport", 169 | "/actions/default/out/Haptic": "Haptic", 170 | "/actions/platformer/in/Jump": "Jump", 171 | "/actions/default/in/SnapTurnLeft": "Snap Turn (Left)", 172 | "/actions/default/in/SnapTurnRight": "Snap Turn (Right)" 173 | } 174 | ] 175 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Behaviour_SkeletonCustom.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | /// 8 | /// The major difference between this component and the standard SteamVR_Behaviour_Skeleton is this one lets you 9 | /// only use the joints you care about. You can set the transforms you're concerned with and ignore the ones you're not. 10 | /// 11 | public class SteamVR_Behaviour_SkeletonCustom : SteamVR_Behaviour_Skeleton 12 | { 13 | static SteamVR_Behaviour_SkeletonCustom() 14 | { 15 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 16 | } 17 | 18 | // [SerializeField] 19 | protected Transform _wrist; 20 | 21 | // [SerializeField] 22 | protected Transform _thumbMetacarpal; 23 | 24 | // [SerializeField] 25 | protected Transform _thumbProximal; 26 | 27 | // [SerializeField] 28 | protected Transform _thumbMiddle; 29 | 30 | // [SerializeField] 31 | protected Transform _thumbDistal; 32 | 33 | // [SerializeField] 34 | protected Transform _thumbTip; 35 | 36 | // [SerializeField] 37 | protected Transform _thumbAux; 38 | 39 | // [SerializeField] 40 | protected Transform _indexMetacarpal; 41 | 42 | // [SerializeField] 43 | protected Transform _indexProximal; 44 | 45 | // [SerializeField] 46 | protected Transform _indexMiddle; 47 | 48 | // [SerializeField] 49 | protected Transform _indexDistal; 50 | 51 | // [SerializeField] 52 | protected Transform _indexTip; 53 | 54 | // [SerializeField] 55 | protected Transform _indexAux; 56 | 57 | // [SerializeField] 58 | protected Transform _middleMetacarpal; 59 | 60 | // [SerializeField] 61 | protected Transform _middleProximal; 62 | 63 | // [SerializeField] 64 | protected Transform _middleMiddle; 65 | 66 | // [SerializeField] 67 | protected Transform _middleDistal; 68 | 69 | // [SerializeField] 70 | protected Transform _middleTip; 71 | 72 | // [SerializeField] 73 | protected Transform _middleAux; 74 | 75 | // [SerializeField] 76 | protected Transform _ringMetacarpal; 77 | 78 | // [SerializeField] 79 | protected Transform _ringProximal; 80 | 81 | // [SerializeField] 82 | protected Transform _ringMiddle; 83 | 84 | // [SerializeField] 85 | protected Transform _ringDistal; 86 | 87 | // [SerializeField] 88 | protected Transform _ringTip; 89 | 90 | // [SerializeField] 91 | protected Transform _ringAux; 92 | 93 | // [SerializeField] 94 | protected Transform _pinkyMetacarpal; 95 | 96 | // [SerializeField] 97 | protected Transform _pinkyProximal; 98 | 99 | // [SerializeField] 100 | protected Transform _pinkyMiddle; 101 | 102 | // [SerializeField] 103 | protected Transform _pinkyDistal; 104 | 105 | // [SerializeField] 106 | protected Transform _pinkyTip; 107 | 108 | // [SerializeField] 109 | protected Transform _pinkyAux; 110 | 111 | 112 | protected override void AssignBonesArray() 113 | { 114 | bones[SteamVR_Skeleton_JointIndexes.wrist] = _wrist; 115 | bones[SteamVR_Skeleton_JointIndexes.thumbProximal] = _thumbProximal; 116 | bones[SteamVR_Skeleton_JointIndexes.thumbMiddle] = _thumbMiddle; 117 | bones[SteamVR_Skeleton_JointIndexes.thumbDistal] = _thumbDistal; 118 | bones[SteamVR_Skeleton_JointIndexes.thumbTip] = _thumbTip; 119 | bones[SteamVR_Skeleton_JointIndexes.thumbAux] = _thumbAux; 120 | bones[SteamVR_Skeleton_JointIndexes.indexProximal] = _indexProximal; 121 | bones[SteamVR_Skeleton_JointIndexes.indexMiddle] = _indexMiddle; 122 | bones[SteamVR_Skeleton_JointIndexes.indexDistal] = _indexDistal; 123 | bones[SteamVR_Skeleton_JointIndexes.indexTip] = _indexTip; 124 | bones[SteamVR_Skeleton_JointIndexes.indexAux] = _indexAux; 125 | bones[SteamVR_Skeleton_JointIndexes.middleProximal] = _middleProximal; 126 | bones[SteamVR_Skeleton_JointIndexes.middleMiddle] = _middleMiddle; 127 | bones[SteamVR_Skeleton_JointIndexes.middleDistal] = _middleDistal; 128 | bones[SteamVR_Skeleton_JointIndexes.middleTip] = _middleTip; 129 | bones[SteamVR_Skeleton_JointIndexes.middleAux] = _middleAux; 130 | bones[SteamVR_Skeleton_JointIndexes.ringProximal] = _ringProximal; 131 | bones[SteamVR_Skeleton_JointIndexes.ringMiddle] = _ringMiddle; 132 | bones[SteamVR_Skeleton_JointIndexes.ringDistal] = _ringDistal; 133 | bones[SteamVR_Skeleton_JointIndexes.ringTip] = _ringTip; 134 | bones[SteamVR_Skeleton_JointIndexes.ringAux] = _ringAux; 135 | bones[SteamVR_Skeleton_JointIndexes.pinkyProximal] = _pinkyProximal; 136 | bones[SteamVR_Skeleton_JointIndexes.pinkyMiddle] = _pinkyMiddle; 137 | bones[SteamVR_Skeleton_JointIndexes.pinkyDistal] = _pinkyDistal; 138 | bones[SteamVR_Skeleton_JointIndexes.pinkyTip] = _pinkyTip; 139 | bones[SteamVR_Skeleton_JointIndexes.pinkyAux] = _pinkyAux; 140 | } 141 | } 142 | } -------------------------------------------------------------------------------- /HC_VRTrial/VRUtils/VRCamera.cs: -------------------------------------------------------------------------------- 1 | using Il2CppInterop.Runtime.Injection; 2 | using Il2CppInterop.Runtime.Attributes; 3 | using UnityEngine; 4 | using Valve.VR; 5 | 6 | using HC_VRTrial.Logging; 7 | 8 | namespace HC_VRTrial.VRUtils 9 | { 10 | /// 11 | /// A VR camera capable of projecting images onto the HMD and supporting HMD tracking. 12 | /// 13 | /// The internal structure of the game objects is as follows: 14 | /// - parentGameObject 15 | /// - Origin: VR Camera's origin 16 | /// - Camera: Normal and VR Camera 17 | /// 18 | public class VRCamera : MonoBehaviour 19 | { 20 | static VRCamera() { ClassInjector.RegisterTypeInIl2Cpp(); } 21 | 22 | public static VRCamera Create(GameObject parentGameObject, string name, int depth) 23 | { 24 | var gameObject = new GameObject($"{parentGameObject.name}{name}Origin"); 25 | // Ensure the lifecycle of the GameObject is synchronized with its parent. 26 | gameObject.transform.parent = parentGameObject.transform; 27 | gameObject.SetActive(false); 28 | var result = gameObject.AddComponent(); 29 | result.Depth = depth; 30 | gameObject.SetActive(true); 31 | return result; 32 | } 33 | 34 | public static bool IsBaseHeadSet { get; private set; } = false; 35 | public static Vector3 BaseHeadPosition { get; private set; } = Vector3.zero; 36 | public static Quaternion BaseHeadRotation { get; private set; } = Quaternion.identity; 37 | 38 | /// 39 | /// Sets the current head position and rotation as the center point for future viewpoints. 40 | /// 41 | public static void UpdateViewport(VRCamera vrCamera) 42 | { 43 | IsBaseHeadSet = true; 44 | BaseHeadPosition = vrCamera.VR.head.localPosition; 45 | var orientationEulerAngles = vrCamera.VR.head.localRotation.eulerAngles; 46 | BaseHeadRotation = Quaternion.Euler( 47 | PluginConfig.ReflectHMDRotationXOnViewport.Value ? orientationEulerAngles.x : 0, 48 | PluginConfig.ReflectHMDRotationYOnViewport.Value ? orientationEulerAngles.y : 0, 49 | PluginConfig.ReflectHMDRotationZOnViewport.Value ? orientationEulerAngles.z : 0); 50 | } 51 | 52 | private int Depth { get; set; } 53 | private GameObject CameraObject { get; set; } 54 | public Camera Normal { get; private set; } 55 | [HideFromIl2Cpp] public SteamVR_Camera VR { get; private set; } 56 | 57 | void Awake() 58 | { 59 | PluginLog.Debug($"Awake: {name}"); 60 | Setup(); 61 | } 62 | 63 | void OnDestroy() 64 | { 65 | PluginLog.Debug($"OnDestroy: {name}"); 66 | } 67 | 68 | private void Setup() 69 | { 70 | if (!CameraObject) 71 | { 72 | CameraObject = new GameObject($"{name}Camera"); 73 | // Ensure the lifecycle of the GameObject is synchronized with its parent. 74 | CameraObject.transform.parent = gameObject.transform; 75 | } 76 | 77 | // Prepare a VR camera separate from the game camera to minimize the impact on the game. 78 | if (!CameraObject.GetComponent()) 79 | { 80 | Normal = CameraObject.AddComponent(); 81 | Normal.depth = Depth; 82 | } 83 | 84 | // By combining Camera and SteamVR_Camera, the player can see the camera's view from the HMD. 85 | if (!CameraObject.GetComponent()) VR = CameraObject.AddComponent(); 86 | // When SteamVR_TrackedObject is also combined, the camera moves with the movement of the HMD. 87 | if (!CameraObject.GetComponent()) CameraObject.AddComponent(); 88 | 89 | // After that, just move the camera as you like. 90 | // This project camera usage is just one example. 91 | } 92 | 93 | /// 94 | /// Hijacks the viewpoint of a camera and displays it through the VR camera. 95 | /// 96 | /// The target camera. 97 | /// If true, copies the camera settings using Camera.CopyFrom. Specify false to adjust the camera settings independently. 98 | /// If true, synchronizes some of the camera settings in real-time. Refer to CameraHijacker.Synchronize for detailed synchronization content. 99 | public void Hijack(Camera targetCamera, bool useCopyFrom = true, bool synchronization = true) 100 | { 101 | Setup(); 102 | 103 | if (targetCamera != null) 104 | { 105 | CameraHijacker.Hijack(targetCamera, Normal, useCopyFrom, synchronization); 106 | 107 | // Set origin to the inverse position of the base head from the target camera. 108 | // The origin of the VR camera is the center of the play area (Usually at the player's feet). 109 | VR.origin.rotation = targetCamera.transform.rotation * Quaternion.Inverse(BaseHeadRotation); 110 | VR.origin.position = targetCamera.transform.position - VR.origin.rotation * BaseHeadPosition; 111 | VR.origin.SetParent(targetCamera.transform); 112 | } 113 | 114 | Normal.depth = Depth; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Skeleton_Pose.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using System; 4 | using UnityEngine; 5 | 6 | using System.Linq; 7 | 8 | namespace Valve.VR 9 | { 10 | public class SteamVR_Skeleton_Pose : ScriptableObject 11 | { 12 | static SteamVR_Skeleton_Pose() 13 | { 14 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 15 | } 16 | 17 | public SteamVR_Skeleton_Pose_Hand leftHand = new SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources.LeftHand); 18 | public SteamVR_Skeleton_Pose_Hand rightHand = new SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources.RightHand); 19 | 20 | protected const int leftHandInputSource = (int)SteamVR_Input_Sources.LeftHand; 21 | protected const int rightHandInputSource = (int)SteamVR_Input_Sources.RightHand; 22 | 23 | public bool applyToSkeletonRoot = true; 24 | 25 | public SteamVR_Skeleton_Pose_Hand GetHand(int hand) 26 | { 27 | if (hand == leftHandInputSource) 28 | return leftHand; 29 | else if (hand == rightHandInputSource) 30 | return rightHand; 31 | return null; 32 | } 33 | 34 | public SteamVR_Skeleton_Pose_Hand GetHand(SteamVR_Input_Sources hand) 35 | { 36 | if (hand == SteamVR_Input_Sources.LeftHand) 37 | return leftHand; 38 | else if (hand == SteamVR_Input_Sources.RightHand) 39 | return rightHand; 40 | return null; 41 | } 42 | } 43 | 44 | [Serializable] 45 | public class SteamVR_Skeleton_Pose_Hand 46 | { 47 | public SteamVR_Input_Sources inputSource; 48 | 49 | public SteamVR_Skeleton_FingerExtensionTypes thumbFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static; 50 | public SteamVR_Skeleton_FingerExtensionTypes indexFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static; 51 | public SteamVR_Skeleton_FingerExtensionTypes middleFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static; 52 | public SteamVR_Skeleton_FingerExtensionTypes ringFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static; 53 | public SteamVR_Skeleton_FingerExtensionTypes pinkyFingerMovementType = SteamVR_Skeleton_FingerExtensionTypes.Static; 54 | 55 | /// 56 | /// Get extension type for a particular finger. Thumb is 0, Index is 1, etc. 57 | /// 58 | public SteamVR_Skeleton_FingerExtensionTypes GetFingerExtensionType(int finger) 59 | { 60 | if (finger == 0) 61 | return thumbFingerMovementType; 62 | if (finger == 1) 63 | return indexFingerMovementType; 64 | if (finger == 2) 65 | return middleFingerMovementType; 66 | if (finger == 3) 67 | return ringFingerMovementType; 68 | if (finger == 4) 69 | return pinkyFingerMovementType; 70 | 71 | //default to static 72 | Debug.LogWarning("Finger not in range!"); 73 | return SteamVR_Skeleton_FingerExtensionTypes.Static; 74 | } 75 | 76 | public bool ignoreRootPoseData = true; 77 | public bool ignoreWristPoseData = true; 78 | 79 | public Vector3 position; 80 | public Quaternion rotation; 81 | 82 | public Vector3[] bonePositions; 83 | public Quaternion[] boneRotations; 84 | 85 | public SteamVR_Skeleton_Pose_Hand(SteamVR_Input_Sources source) 86 | { 87 | inputSource = source; 88 | } 89 | 90 | public SteamVR_Skeleton_FingerExtensionTypes GetMovementTypeForBone(int boneIndex) 91 | { 92 | int fingerIndex = SteamVR_Skeleton_JointIndexes.GetFingerForBone(boneIndex); 93 | 94 | switch (fingerIndex) 95 | { 96 | case SteamVR_Skeleton_FingerIndexes.thumb: 97 | return thumbFingerMovementType; 98 | 99 | case SteamVR_Skeleton_FingerIndexes.index: 100 | return indexFingerMovementType; 101 | 102 | case SteamVR_Skeleton_FingerIndexes.middle: 103 | return middleFingerMovementType; 104 | 105 | case SteamVR_Skeleton_FingerIndexes.ring: 106 | return ringFingerMovementType; 107 | 108 | case SteamVR_Skeleton_FingerIndexes.pinky: 109 | return pinkyFingerMovementType; 110 | } 111 | 112 | return SteamVR_Skeleton_FingerExtensionTypes.Static; 113 | } 114 | } 115 | 116 | public enum SteamVR_Skeleton_FingerExtensionTypes 117 | { 118 | Static, 119 | Free, 120 | Extend, 121 | Contract, 122 | } 123 | 124 | public class SteamVR_Skeleton_FingerExtensionTypeLists 125 | { 126 | private SteamVR_Skeleton_FingerExtensionTypes[] _enumList; 127 | public SteamVR_Skeleton_FingerExtensionTypes[] enumList 128 | { 129 | get 130 | { 131 | if (_enumList == null) 132 | _enumList = (SteamVR_Skeleton_FingerExtensionTypes[])System.Enum.GetValues(typeof(SteamVR_Skeleton_FingerExtensionTypes)); 133 | return _enumList; 134 | } 135 | } 136 | 137 | private string[] _stringList; 138 | public string[] stringList 139 | { 140 | get 141 | { 142 | if (_stringList == null) 143 | _stringList = enumList.Select(element => element.ToString()).ToArray(); 144 | return _stringList; 145 | } 146 | } 147 | } 148 | } -------------------------------------------------------------------------------- /SteamVRLib_Unity.XR.OpenVR/OpenVREvents.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Events; 3 | using Valve.VR; 4 | 5 | namespace Unity.XR.OpenVR 6 | { 7 | public class OpenVREvent : UnityEvent { } 8 | public class OpenVREvents 9 | { 10 | private static OpenVREvents instance; 11 | 12 | //dictionaries are slow/allocate in mono for some reason. So we just allocate a bunch at the beginning. 13 | private OpenVREvent[] events; 14 | private int[] eventIndicies; 15 | private VREvent_t vrEvent; 16 | private uint vrEventSize; 17 | 18 | private bool preloadedEvents = false; 19 | 20 | private const int maxEventsPerUpdate = 64; 21 | private static bool debugLogAllEvents = false; 22 | 23 | private static bool enabled = true; 24 | 25 | public static void Initialize(bool lazyLoadEvents = false) 26 | { 27 | instance = new OpenVREvents(lazyLoadEvents); 28 | } 29 | 30 | public bool IsInitialized() 31 | { 32 | return instance != null; 33 | } 34 | 35 | public OpenVREvents(bool lazyLoadEvents = false) 36 | { 37 | if (OpenVRHelpers.IsUsingSteamVRInput()) 38 | { 39 | enabled = false; //let the steamvr plugin handle events 40 | return; 41 | } 42 | 43 | instance = this; 44 | events = new OpenVREvent[(int)EVREventType.VREvent_VendorSpecific_Reserved_End]; 45 | 46 | vrEvent = new VREvent_t(); 47 | vrEventSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t)); 48 | 49 | if (lazyLoadEvents == false) 50 | { 51 | for (int eventIndex = 0; eventIndex < events.Length; eventIndex++) 52 | { 53 | events[eventIndex] = new OpenVREvent(); 54 | } 55 | } 56 | else 57 | { 58 | preloadedEvents = true; 59 | } 60 | 61 | RegisterDefaultEvents(); 62 | } 63 | 64 | public void RegisterDefaultEvents() 65 | { 66 | AddListener(EVREventType.VREvent_Quit, (UnityAction)On_VREvent_Quit); 67 | } 68 | 69 | public static void AddListener(EVREventType eventType, UnityAction action, bool removeOtherListeners = false) 70 | { 71 | instance.Add(eventType, action, removeOtherListeners); 72 | } 73 | public void Add(EVREventType eventType, UnityAction action, bool removeOtherListeners = false) 74 | { 75 | if (!enabled) 76 | { 77 | Debug.LogError("[OpenVR XR Plugin] This events class is currently not enabled, please use SteamVR_Events instead."); 78 | return; 79 | } 80 | 81 | int eventIndex = (int)eventType; 82 | if (preloadedEvents == false && events[eventIndex] == null) 83 | { 84 | events[eventIndex] = new OpenVREvent(); 85 | } 86 | 87 | if (removeOtherListeners) 88 | { 89 | events[eventIndex].RemoveAllListeners(); 90 | } 91 | 92 | events[eventIndex].AddListener(action); 93 | } 94 | 95 | public static void RemoveListener(EVREventType eventType, UnityAction action) 96 | { 97 | instance.Remove(eventType, action); 98 | } 99 | public void Remove(EVREventType eventType, UnityAction action) 100 | { 101 | int eventIndex = (int)eventType; 102 | if (preloadedEvents || events[eventIndex] != null) 103 | { 104 | events[eventIndex].RemoveListener(action); 105 | } 106 | } 107 | 108 | public static void Update() 109 | { 110 | instance.PollEvents(); 111 | } 112 | 113 | public void PollEvents() 114 | { 115 | if (Valve.VR.OpenVR.System != null && enabled) 116 | { 117 | for (int eventIndex = 0; eventIndex < maxEventsPerUpdate; eventIndex++) 118 | { 119 | if (Valve.VR.OpenVR.System == null || !Valve.VR.OpenVR.System.PollNextEvent(ref vrEvent, vrEventSize)) 120 | break; 121 | 122 | int uEventType = (int)vrEvent.eventType; 123 | 124 | if (debugLogAllEvents) 125 | { 126 | EVREventType eventType = (EVREventType)uEventType; 127 | Debug.Log(string.Format("[{0}] {1}", Time.frameCount, eventType.ToString())); 128 | } 129 | 130 | if (events[uEventType] != null) 131 | { 132 | events[uEventType].Invoke(vrEvent); 133 | } 134 | } 135 | } 136 | } 137 | 138 | private bool exiting = false; 139 | 140 | #region DefaultEvents 141 | private void On_VREvent_Quit(VREvent_t pEvent) 142 | { 143 | if (exiting == true) 144 | { 145 | return; 146 | } 147 | exiting = true; 148 | 149 | if (Valve.VR.OpenVR.System != null) 150 | { 151 | Valve.VR.OpenVR.System.AcknowledgeQuit_Exiting(); 152 | } 153 | 154 | #if UNITY_EDITOR 155 | Debug.Log("[OpenVR] Quit requested from OpenVR. Exiting application via EditorApplication.isPlaying = false"); 156 | UnityEditor.EditorApplication.isPlaying = false; 157 | #else 158 | Debug.Log("[OpenVR] Quit requested from OpenVR. Exiting application via Application.Quit"); 159 | Application.Quit(); 160 | #endif 161 | } 162 | #endregion 163 | } 164 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_ActionSet_Manager.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | using System; 5 | using System.Runtime.InteropServices; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace Valve.VR 10 | { 11 | /// 12 | /// Action sets are logical groupings of actions. Multiple sets can be active at one time. 13 | /// 14 | public static class SteamVR_ActionSet_Manager 15 | { 16 | public static VRActiveActionSet_t[] rawActiveActionSetArray; 17 | 18 | [NonSerialized] 19 | private static uint activeActionSetSize; 20 | 21 | private static bool changed = false; 22 | 23 | public static void Initialize() 24 | { 25 | activeActionSetSize = (uint)(Marshal.SizeOf(typeof(VRActiveActionSet_t))); 26 | } 27 | 28 | /// 29 | /// Disable all known action sets. 30 | /// 31 | public static void DisableAllActionSets() 32 | { 33 | for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++) 34 | { 35 | SteamVR_Input.actionSets[actionSetIndex].Deactivate(SteamVR_Input_Sources.Any); 36 | SteamVR_Input.actionSets[actionSetIndex].Deactivate(SteamVR_Input_Sources.LeftHand); 37 | SteamVR_Input.actionSets[actionSetIndex].Deactivate(SteamVR_Input_Sources.RightHand); 38 | } 39 | } 40 | 41 | private static int lastFrameUpdated; 42 | public static void UpdateActionStates(bool force = false) 43 | { 44 | if (force || Time.frameCount != lastFrameUpdated) 45 | { 46 | lastFrameUpdated = Time.frameCount; 47 | 48 | if (changed) 49 | { 50 | UpdateActionSetsArray(); 51 | } 52 | 53 | if (rawActiveActionSetArray != null && rawActiveActionSetArray.Length > 0) 54 | { 55 | if (OpenVR.Input != null) 56 | { 57 | EVRInputError err = OpenVR.Input.UpdateActionState(rawActiveActionSetArray, activeActionSetSize); 58 | if (err != EVRInputError.None) 59 | Debug.LogError("[SteamVR] UpdateActionState error: " + err.ToString()); 60 | //else Debug.Log("Action sets activated: " + activeActionSets.Length); 61 | } 62 | } 63 | else 64 | { 65 | //Debug.LogWarning("No sets active"); 66 | } 67 | } 68 | } 69 | 70 | public static void SetChanged() 71 | { 72 | changed = true; 73 | } 74 | 75 | private static void UpdateActionSetsArray() 76 | { 77 | List activeActionSetsList = new List(); 78 | 79 | SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetAllSources(); 80 | 81 | for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++) 82 | { 83 | SteamVR_ActionSet set = SteamVR_Input.actionSets[actionSetIndex]; 84 | 85 | for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) 86 | { 87 | SteamVR_Input_Sources source = sources[sourceIndex]; 88 | 89 | if (set.ReadRawSetActive(source)) 90 | { 91 | VRActiveActionSet_t activeSet = new VRActiveActionSet_t(); 92 | activeSet.ulActionSet = set.handle; 93 | activeSet.nPriority = set.ReadRawSetPriority(source); 94 | activeSet.ulRestrictedToDevice = SteamVR_Input_Source.GetHandle(source); 95 | 96 | int insertionIndex = 0; 97 | for (insertionIndex = 0; insertionIndex < activeActionSetsList.Count; insertionIndex++) 98 | { 99 | if (activeActionSetsList[insertionIndex].nPriority > activeSet.nPriority) 100 | break; 101 | } 102 | activeActionSetsList.Insert(insertionIndex, activeSet); 103 | } 104 | } 105 | } 106 | 107 | changed = false; 108 | 109 | rawActiveActionSetArray = activeActionSetsList.ToArray(); 110 | 111 | if (Application.isEditor || updateDebugTextInBuilds) 112 | UpdateDebugText(); 113 | } 114 | 115 | public static SteamVR_ActionSet GetSetFromHandle(ulong handle) 116 | { 117 | for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++) 118 | { 119 | SteamVR_ActionSet set = SteamVR_Input.actionSets[actionSetIndex]; 120 | if (set.handle == handle) 121 | return set; 122 | } 123 | 124 | return null; 125 | } 126 | 127 | public static string debugActiveSetListText; 128 | public static bool updateDebugTextInBuilds = false; 129 | private static void UpdateDebugText() 130 | { 131 | StringBuilder stringBuilder = new StringBuilder(); 132 | 133 | for (int activeIndex = 0; activeIndex < rawActiveActionSetArray.Length; activeIndex++) 134 | { 135 | VRActiveActionSet_t set = rawActiveActionSetArray[activeIndex]; 136 | stringBuilder.Append(set.nPriority); 137 | stringBuilder.Append("\t"); 138 | stringBuilder.Append(SteamVR_Input_Source.GetSource(set.ulRestrictedToDevice)); 139 | stringBuilder.Append("\t"); 140 | stringBuilder.Append(GetSetFromHandle(set.ulActionSet).GetShortName()); 141 | stringBuilder.Append("\n"); 142 | } 143 | 144 | debugActiveSetListText = stringBuilder.ToString(); 145 | } 146 | } 147 | } -------------------------------------------------------------------------------- /HC_VRTrial/SimpleVRController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Text.RegularExpressions; 3 | 4 | using BepInEx.Unity.IL2CPP.Utils; 5 | using Il2CppInterop.Runtime.Attributes; 6 | using Il2CppInterop.Runtime.Injection; 7 | using UnityEngine; 8 | 9 | using HC_VRTrial.Logging; 10 | using HC_VRTrial.VRUtils; 11 | 12 | namespace HC_VRTrial 13 | { 14 | public class SimpleVRController : MonoBehaviour 15 | { 16 | static SimpleVRController() { ClassInjector.RegisterTypeInIl2Cpp(); } 17 | 18 | // Layer: These layers should be exclusive to the VR UI to prevent interference with game's main rendering layers. 19 | // for UGUI capture work 20 | public const int UGUI_CAPTURE_LAYER = 15; 21 | // for UI screen camera 22 | public const int UI_SCREEN_LAYER = 31; 23 | 24 | // Camera depth: Set the output after the game camera. 25 | public const int MAIN_VR_CAMERA_DEPTH = 1000; 26 | public const int UI_SCREEN_CAMERA_DEPTH = MAIN_VR_CAMERA_DEPTH + 10; 27 | 28 | // Distance from player to UI screen, in meters. 29 | public const float UI_SCREEN_DISTANCE = 1.0f; 30 | 31 | [HideFromIl2Cpp] public VRCamera MainVRCamera { get; private set; } 32 | [HideFromIl2Cpp] public UIScreen UIScreen { get; private set; } 33 | 34 | void Awake() 35 | { 36 | PluginLog.Debug($"Awake: {name}"); 37 | 38 | // MainVRCamera is a camera that displays 3D space. 39 | MainVRCamera = VRCamera.Create(gameObject, nameof(MainVRCamera), MAIN_VR_CAMERA_DEPTH); 40 | 41 | // UIScreen displays the texture as a screen using the built-in VRCamera. 42 | // Also projects the mouse cursor onto the 3D screen. 43 | UIScreen = UIScreen.Create(gameObject, nameof(UIScreen), UI_SCREEN_CAMERA_DEPTH, UI_SCREEN_LAYER, 44 | new UIScreenPanel[] { 45 | new(UGUICapture.Create(gameObject, nameof(UGUICapture), UGUI_CAPTURE_LAYER).Texture), 46 | new(IMGUICapture.Create(gameObject, nameof(IMGUICapture)).Texture, -0.001f * Vector3.forward, Vector3.one), 47 | }); 48 | 49 | this.StartCoroutine(Setup()); 50 | } 51 | 52 | void OnDestroy() 53 | { 54 | PluginLog.Debug($"OnDestroy: {name}"); 55 | } 56 | 57 | [HideFromIl2Cpp] 58 | IEnumerator Setup() 59 | { 60 | // Delays setup to ensure accurate HMD tracking initialization. 61 | yield return new WaitForSeconds(0.1f); 62 | 63 | UpdateCamera(false); 64 | } 65 | 66 | [HideFromIl2Cpp] 67 | void UpdateCamera(bool forceUpdateOrientationPose) 68 | { 69 | if (!VRCamera.IsBaseHeadSet || forceUpdateOrientationPose) VRCamera.UpdateViewport(MainVRCamera); 70 | 71 | // Redirects the main game camera's view to the MainVRCamera 72 | // and positions the UIScreen at a specified distance in front of it, 73 | // ensuring it remains static relative to the player's head movement. 74 | MainVRCamera.Hijack(Camera.main); 75 | UIScreen.LinkToFront(MainVRCamera, UI_SCREEN_DISTANCE); 76 | } 77 | 78 | private float LastClickTime { get; set; } = -1f; 79 | 80 | void Update() 81 | { 82 | UpdateViewport(); 83 | OptimizeVRExperience(); 84 | } 85 | 86 | void UpdateViewport() 87 | { 88 | // Update the viewport with a double-click of the right mouse button. 89 | if (0f < PluginConfig.DoubleClickIntervalToUpdateViewport.Value && Input.GetMouseButtonDown(1)) 90 | { 91 | var currentTime = Time.time; 92 | if (currentTime - LastClickTime <= PluginConfig.DoubleClickIntervalToUpdateViewport.Value) 93 | { 94 | UpdateCamera(true); 95 | LastClickTime = 0f; 96 | } 97 | else 98 | { 99 | LastClickTime = currentTime; 100 | } 101 | } 102 | } 103 | 104 | void OptimizeVRExperience() 105 | { 106 | // #2: Improved the discomfort between the left and right eyes: Shadows and lights. 107 | if (PluginConfig.DisableLights.Value) 108 | { 109 | foreach (var i in FindObjectsOfType()) 110 | { 111 | if (i.shadows != LightShadows.None) 112 | { 113 | PluginLog.Info($"Disable Light shadows: {i.name}"); 114 | i.shadows = LightShadows.None; 115 | } 116 | if (i.enabled && (i.type == LightType.Spot || i.type == LightType.Point)) 117 | { 118 | PluginLog.Info($"Disable Light: {i.name}"); 119 | i.enabled = false; 120 | } 121 | } 122 | } 123 | 124 | // #3: Improved the discomfort between the left and right eyes: Plants. 125 | if (PluginConfig.DisableLODGroups.Value) 126 | { 127 | foreach (var i in FindObjectsOfType()) 128 | { 129 | if (1 < i.lodCount) 130 | { 131 | PluginLog.Info($"Disable LODGroup: {i.name}"); 132 | i.SetLODs(new LOD[] { i.GetLODs()[0] }); 133 | i.RecalculateBounds(); 134 | } 135 | } 136 | } 137 | 138 | // #10: Improved the discomfort between the left and right eyes: Particles. 139 | if (PluginConfig.DisableParticleSystems.Value) 140 | { 141 | foreach (var i in FindObjectsOfType()) 142 | { 143 | if (Regex.IsMatch(i.name, PluginConfig.ParticleNameDisableRegex.Value)) 144 | { 145 | PluginLog.Info($"Disable ParticleSystem: {i.name}"); 146 | i.gameObject.SetActive(false); 147 | } 148 | } 149 | } 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Behaviour_Vector3.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | public class SteamVR_Behaviour_Vector3 : MonoBehaviour 8 | { 9 | static SteamVR_Behaviour_Vector3() 10 | { 11 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 12 | } 13 | 14 | /// The vector3 action to get data from 15 | public SteamVR_Action_Vector3 vector3Action; 16 | 17 | /// The device this action applies to. Any if the action is not device specific. 18 | // [Tooltip("The device this action should apply to. Any if the action is not device specific.")] 19 | public SteamVR_Input_Sources inputSource; 20 | 21 | /// Unity event that fires whenever the action's value has changed since the last update. 22 | // [Tooltip("Fires whenever the action's value has changed since the last update.")] 23 | public SteamVR_Behaviour_Vector3Event onChange; 24 | 25 | /// Unity event that fires whenever the action's value has been updated 26 | // [Tooltip("Fires whenever the action's value has been updated.")] 27 | public SteamVR_Behaviour_Vector3Event onUpdate; 28 | 29 | /// Unity event that fires whenever the action's value has been updated and is non-zero 30 | // [Tooltip("Fires whenever the action's value has been updated and is non-zero.")] 31 | public SteamVR_Behaviour_Vector3Event onAxis; 32 | 33 | /// C# event that fires whenever the action's value has changed since the last update. 34 | public ChangeHandler onChangeEvent; 35 | 36 | /// C# event that fires whenever the action's value has been updated 37 | public UpdateHandler onUpdateEvent; 38 | 39 | /// C# event that fires whenever the action's value has been updated and is non-zero 40 | public AxisHandler onAxisEvent; 41 | 42 | 43 | /// Returns whether this action is bound and the action set is active 44 | public bool isActive { get { return vector3Action.GetActive(inputSource); } } 45 | 46 | protected virtual void OnEnable() 47 | { 48 | if (vector3Action == null) 49 | { 50 | Debug.LogError("[SteamVR] Vector3 action not set.", this); 51 | return; 52 | } 53 | 54 | AddHandlers(); 55 | } 56 | 57 | protected virtual void OnDisable() 58 | { 59 | RemoveHandlers(); 60 | } 61 | 62 | protected void AddHandlers() 63 | { 64 | vector3Action[inputSource].onUpdate += SteamVR_Behaviour_Vector3_OnUpdate; 65 | vector3Action[inputSource].onChange += SteamVR_Behaviour_Vector3_OnChange; 66 | vector3Action[inputSource].onAxis += SteamVR_Behaviour_Vector3_OnAxis; 67 | } 68 | 69 | protected void RemoveHandlers() 70 | { 71 | if (vector3Action != null) 72 | { 73 | vector3Action[inputSource].onUpdate -= SteamVR_Behaviour_Vector3_OnUpdate; 74 | vector3Action[inputSource].onChange -= SteamVR_Behaviour_Vector3_OnChange; 75 | vector3Action[inputSource].onAxis -= SteamVR_Behaviour_Vector3_OnAxis; 76 | } 77 | } 78 | 79 | private void SteamVR_Behaviour_Vector3_OnUpdate(SteamVR_Action_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta) 80 | { 81 | if (onUpdate != null) 82 | { 83 | onUpdate.Send(this, fromSource, newAxis, newDelta); 84 | } 85 | if (onUpdateEvent != null) 86 | { 87 | onUpdateEvent.Invoke(this, fromSource, newAxis, newDelta); 88 | } 89 | } 90 | 91 | private void SteamVR_Behaviour_Vector3_OnChange(SteamVR_Action_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta) 92 | { 93 | if (onChange != null) 94 | { 95 | onChange.Send(this, fromSource, newAxis, newDelta); 96 | } 97 | if (onChangeEvent != null) 98 | { 99 | onChangeEvent.Invoke(this, fromSource, newAxis, newDelta); 100 | } 101 | } 102 | 103 | private void SteamVR_Behaviour_Vector3_OnAxis(SteamVR_Action_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta) 104 | { 105 | if (onAxis != null) 106 | { 107 | onAxis.Send(this, fromSource, newAxis, newDelta); 108 | } 109 | if (onAxisEvent != null) 110 | { 111 | onAxisEvent.Invoke(this, fromSource, newAxis, newDelta); 112 | } 113 | } 114 | 115 | /// 116 | /// Gets the localized name of the device that the action corresponds to. 117 | /// 118 | /// 119 | /// 120 | /// VRInputString_Hand - Which hand the origin is in. E.g. "Left Hand" 121 | /// VRInputString_ControllerType - What kind of controller the user has in that hand.E.g. "Vive Controller" 122 | /// VRInputString_InputSource - What part of that controller is the origin. E.g. "Trackpad" 123 | /// VRInputString_All - All of the above. E.g. "Left Hand Vive Controller Trackpad" 124 | /// 125 | /// 126 | public string GetLocalizedName(params EVRInputStringBits[] localizedParts) 127 | { 128 | if (vector3Action != null) 129 | return vector3Action.GetLocalizedOriginPart(inputSource, localizedParts); 130 | return null; 131 | } 132 | 133 | public delegate void AxisHandler(SteamVR_Behaviour_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta); 134 | public delegate void ChangeHandler(SteamVR_Behaviour_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta); 135 | public delegate void UpdateHandler(SteamVR_Behaviour_Vector3 fromAction, SteamVR_Input_Sources fromSource, Vector3 newAxis, Vector3 newDelta); 136 | } 137 | } -------------------------------------------------------------------------------- /SteamVRLib_UnityEngine.XR.Management/XRLoaderHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | #if UNITY_EDITOR 5 | using UnityEditor; 6 | #endif 7 | 8 | namespace UnityEngine.XR.Management 9 | { 10 | /// 11 | /// XR Loader abstract subclass used as a base class for specific provider implementations. Class provides some 12 | /// helper logic that can be used to handle subsystem handling in a typesafe manner, reducing potential boilerplate 13 | /// code. 14 | /// 15 | public abstract class XRLoaderHelper : XRLoader 16 | { 17 | /// 18 | /// Map of loaded susbsystems. Used so we don't always have to fo to XRSubsystemManger and do a manual 19 | /// search to find the instance we loaded. 20 | /// 21 | protected Dictionary m_IntegratedSubsystemInstanceMap = new Dictionary(); 22 | 23 | /// 24 | /// Gets the loaded subsystem of the specified type. Implementation dependent as only implemetnations 25 | /// know what they have loaded and how best to get it.. 26 | /// 27 | /// 28 | /// Type of the subsystem to get. 29 | /// 30 | /// The loaded subsystem or null if not found. 31 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 32 | public override IntegratedSubsystem GetLoadedIntegratedSubsystem(string id) 33 | { 34 | IntegratedSubsystem subsystem; 35 | m_IntegratedSubsystemInstanceMap.TryGetValue(id, out subsystem); 36 | return subsystem; 37 | } 38 | 39 | /// 40 | /// Start a subsystem instance of a given type. Subsystem assumed to already be loaded from 41 | /// a previous call to CreateSubsystem 42 | /// 43 | /// 44 | /// A subclass of 45 | protected void StartIntegratedSubsystem(string id) 46 | { 47 | var subsystem = GetLoadedIntegratedSubsystem(id); 48 | if (subsystem != null) 49 | subsystem.Start(); 50 | } 51 | 52 | /// 53 | /// Stop a subsystem instance of a given type. Subsystem assumed to already be loaded from 54 | /// a previous call to CreateSubsystem 55 | /// 56 | /// 57 | /// A subclass of 58 | protected void StopIntegratedSubsystem(string id) 59 | { 60 | var subsystem = GetLoadedIntegratedSubsystem(id); 61 | if (subsystem != null) 62 | subsystem.Stop(); 63 | } 64 | 65 | /// 66 | /// Destroy a subsystem instance of a given type. Subsystem assumed to already be loaded from 67 | /// a previous call to CreateSubsystem 68 | /// 69 | /// 70 | /// A subclass of 71 | protected void DestroyIntegratedSubsystem(string id) 72 | { 73 | var subsystem = GetLoadedIntegratedSubsystem(id); 74 | if (subsystem != null) 75 | { 76 | if (m_IntegratedSubsystemInstanceMap.ContainsKey(id)) 77 | m_IntegratedSubsystemInstanceMap.Remove(id); 78 | UnityEngineExtensions.IntegratedSubsystemExtensions.Destroy(subsystem); 79 | } 80 | } 81 | 82 | /// 83 | /// Creates a subsystem given a list of descriptors and a specific subsystem id. 84 | /// 85 | /// You should make sure to destroy any subsystem that you created so that resources 86 | /// acquired by your subsystems are correctly cleaned up and released. This is especially important 87 | /// if you create them during initialization, but initialization fails. If that happens, 88 | /// you should clean up any subsystems created up to that point. 89 | /// 90 | /// 91 | /// The descriptor type being passed in. 92 | /// The subsystem type being requested 93 | /// List of TDescriptor instances to use for subsystem matching. 94 | /// The identifier key of the particualr subsystem implementation being requested. 95 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 96 | protected void CreateIntegratedSubsystem(List descriptors, string id) 97 | { 98 | if (descriptors == null) 99 | throw new ArgumentNullException("descriptors"); 100 | 101 | UnityEngineExtensions.SubsystemManagerExtensions.GetIntegratedSubsystemDescriptors(descriptors); 102 | 103 | if (descriptors.Count > 0) 104 | { 105 | foreach (var descriptor in descriptors) 106 | { 107 | IntegratedSubsystem subsys = null; 108 | if (String.Compare(descriptor.id, id, true) == 0) 109 | { 110 | subsys = UnityEngineExtensions.IntegratedSubsystemDescriptorExtensions.Create(descriptor); 111 | } 112 | if (subsys != null) 113 | { 114 | m_IntegratedSubsystemInstanceMap[id] = subsys; 115 | break; 116 | } 117 | } 118 | } 119 | } 120 | 121 | /// 122 | /// Override of to provide for clearing the instance map.true 123 | /// 124 | /// If you override this method in your subclass, you must call the base 125 | /// implementation to allow the instance map tp be cleaned up correctly. 126 | /// 127 | /// 128 | /// True if de-initialization was successful. 129 | public override bool Deinitialize() 130 | { 131 | m_IntegratedSubsystemInstanceMap.Clear(); 132 | return base.Deinitialize(); 133 | } 134 | 135 | #if UNITY_EDITOR 136 | virtual public void WasAssignedToBuildTarget(BuildTargetGroup buildTargetGroup) 137 | { 138 | 139 | } 140 | 141 | virtual public void WasUnassignedFromBuildTarget(BuildTargetGroup buildTargetGroup) 142 | { 143 | 144 | } 145 | #endif 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Behaviour_Single.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | /// 8 | /// SteamVR_Behaviour_Single simplifies the use of single actions. It gives an event to subscribe to for when the action has changed. 9 | /// 10 | public class SteamVR_Behaviour_Single : MonoBehaviour 11 | { 12 | static SteamVR_Behaviour_Single() 13 | { 14 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 15 | } 16 | 17 | /// The single action to get data from. 18 | public SteamVR_Action_Single singleAction; 19 | 20 | /// The device this action applies to. Any if the action is not device specific. 21 | // [Tooltip("The device this action should apply to. Any if the action is not device specific.")] 22 | public SteamVR_Input_Sources inputSource; 23 | 24 | /// Unity event that Fires whenever the action's value has changed since the last update. 25 | // [Tooltip("Fires whenever the action's value has changed since the last update.")] 26 | public SteamVR_Behaviour_SingleEvent onChange; 27 | 28 | /// Unity event that Fires whenever the action's value has been updated 29 | // [Tooltip("Fires whenever the action's value has been updated.")] 30 | public SteamVR_Behaviour_SingleEvent onUpdate; 31 | 32 | /// Unity event that Fires whenever the action's value has been updated and is non-zero 33 | // [Tooltip("Fires whenever the action's value has been updated and is non-zero.")] 34 | public SteamVR_Behaviour_SingleEvent onAxis; 35 | 36 | /// C# event that fires whenever the action's value has changed since the last update. 37 | public ChangeHandler onChangeEvent; 38 | 39 | /// C# event that fires whenever the action's value has been updated 40 | public UpdateHandler onUpdateEvent; 41 | 42 | /// C# event that fires whenever the action's value has been updated and is non-zero 43 | public AxisHandler onAxisEvent; 44 | 45 | /// Returns whether this action is bound and the action set is active 46 | public bool isActive { get { return singleAction.GetActive(inputSource); } } 47 | 48 | protected virtual void OnEnable() 49 | { 50 | if (singleAction == null) 51 | { 52 | Debug.LogError("[SteamVR] Single action not set.", this); 53 | return; 54 | } 55 | 56 | AddHandlers(); 57 | } 58 | 59 | protected virtual void OnDisable() 60 | { 61 | RemoveHandlers(); 62 | } 63 | 64 | protected void AddHandlers() 65 | { 66 | singleAction[inputSource].onUpdate += SteamVR_Behaviour_Single_OnUpdate; 67 | singleAction[inputSource].onChange += SteamVR_Behaviour_Single_OnChange; 68 | singleAction[inputSource].onAxis += SteamVR_Behaviour_Single_OnAxis; 69 | } 70 | 71 | protected void RemoveHandlers() 72 | { 73 | if (singleAction != null) 74 | { 75 | singleAction[inputSource].onUpdate -= SteamVR_Behaviour_Single_OnUpdate; 76 | singleAction[inputSource].onChange -= SteamVR_Behaviour_Single_OnChange; 77 | singleAction[inputSource].onAxis -= SteamVR_Behaviour_Single_OnAxis; 78 | } 79 | } 80 | 81 | private void SteamVR_Behaviour_Single_OnUpdate(SteamVR_Action_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta) 82 | { 83 | if (onUpdate != null) 84 | { 85 | onUpdate.Send(this, fromSource, newAxis, newDelta); 86 | } 87 | 88 | if (onUpdateEvent != null) 89 | { 90 | onUpdateEvent.Invoke(this, fromSource, newAxis, newDelta); 91 | } 92 | } 93 | 94 | private void SteamVR_Behaviour_Single_OnChange(SteamVR_Action_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta) 95 | { 96 | if (onChange != null) 97 | { 98 | onChange.Send(this, fromSource, newAxis, newDelta); 99 | } 100 | 101 | if (onChangeEvent != null) 102 | { 103 | onChangeEvent.Invoke(this, fromSource, newAxis, newDelta); 104 | } 105 | } 106 | 107 | private void SteamVR_Behaviour_Single_OnAxis(SteamVR_Action_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta) 108 | { 109 | if (onAxis != null) 110 | { 111 | onAxis.Send(this, fromSource, newAxis, newDelta); 112 | } 113 | 114 | if (onAxisEvent != null) 115 | { 116 | onAxisEvent.Invoke(this, fromSource, newAxis, newDelta); 117 | } 118 | } 119 | 120 | 121 | /// 122 | /// Gets the localized name of the device that the action corresponds to. 123 | /// 124 | /// 125 | /// 126 | /// VRInputString_Hand - Which hand the origin is in. E.g. "Left Hand" 127 | /// VRInputString_ControllerType - What kind of controller the user has in that hand.E.g. "Vive Controller" 128 | /// VRInputString_InputSource - What part of that controller is the origin. E.g. "Trackpad" 129 | /// VRInputString_All - All of the above. E.g. "Left Hand Vive Controller Trackpad" 130 | /// 131 | /// 132 | public string GetLocalizedName(params EVRInputStringBits[] localizedParts) 133 | { 134 | if (singleAction != null) 135 | return singleAction.GetLocalizedOriginPart(inputSource, localizedParts); 136 | return null; 137 | } 138 | 139 | public delegate void AxisHandler(SteamVR_Behaviour_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta); 140 | public delegate void ChangeHandler(SteamVR_Behaviour_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta); 141 | public delegate void UpdateHandler(SteamVR_Behaviour_Single fromAction, SteamVR_Input_Sources fromSource, float newAxis, float newDelta); 142 | } 143 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Input/SteamVR_Behaviour_Vector2.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | /// 8 | /// Simplifies the use of the Vector2 action. Provides an onChange event that fires whenever the vector2 changes. 9 | /// 10 | public class SteamVR_Behaviour_Vector2 : MonoBehaviour 11 | { 12 | static SteamVR_Behaviour_Vector2() 13 | { 14 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 15 | } 16 | 17 | /// The vector2 action to get data from 18 | public SteamVR_Action_Vector2 vector2Action; 19 | 20 | /// The device this action applies to. Any if the action is not device specific. 21 | // [Tooltip("The device this action should apply to. Any if the action is not device specific.")] 22 | public SteamVR_Input_Sources inputSource; 23 | 24 | /// Unity event that fires whenever the action's value has changed since the last update. 25 | // [Tooltip("Fires whenever the action's value has changed since the last update.")] 26 | public SteamVR_Behaviour_Vector2Event onChange; 27 | 28 | /// Unity event that fires whenever the action's value has been updated 29 | // [Tooltip("Fires whenever the action's value has been updated.")] 30 | public SteamVR_Behaviour_Vector2Event onUpdate; 31 | 32 | /// Unity event that fires whenever the action's value has been updated and is non-zero 33 | // [Tooltip("Fires whenever the action's value has been updated and is non-zero.")] 34 | public SteamVR_Behaviour_Vector2Event onAxis; 35 | 36 | /// C# event that fires whenever the action's value has changed since the last update. 37 | public ChangeHandler onChangeEvent; 38 | 39 | /// C# event that fires whenever the action's value has been updated 40 | public UpdateHandler onUpdateEvent; 41 | 42 | /// C# event that fires whenever the action's value has been updated and is non-zero 43 | public AxisHandler onAxisEvent; 44 | 45 | /// Returns whether this action is bound and the action set is active 46 | public bool isActive { get { return vector2Action.GetActive(inputSource); } } 47 | 48 | protected virtual void OnEnable() 49 | { 50 | if (vector2Action == null) 51 | { 52 | Debug.LogError("[SteamVR] Vector2 action not set.", this); 53 | return; 54 | } 55 | 56 | AddHandlers(); 57 | } 58 | 59 | protected virtual void OnDisable() 60 | { 61 | RemoveHandlers(); 62 | } 63 | 64 | protected void AddHandlers() 65 | { 66 | vector2Action[inputSource].onUpdate += SteamVR_Behaviour_Vector2_OnUpdate; 67 | vector2Action[inputSource].onChange += SteamVR_Behaviour_Vector2_OnChange; 68 | vector2Action[inputSource].onAxis += SteamVR_Behaviour_Vector2_OnAxis; 69 | } 70 | 71 | protected void RemoveHandlers() 72 | { 73 | if (vector2Action != null) 74 | { 75 | vector2Action[inputSource].onUpdate -= SteamVR_Behaviour_Vector2_OnUpdate; 76 | vector2Action[inputSource].onChange -= SteamVR_Behaviour_Vector2_OnChange; 77 | vector2Action[inputSource].onAxis -= SteamVR_Behaviour_Vector2_OnAxis; 78 | } 79 | } 80 | 81 | private void SteamVR_Behaviour_Vector2_OnUpdate(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta) 82 | { 83 | if (onUpdate != null) 84 | { 85 | onUpdate.Send(this, fromSource, newAxis, newDelta); 86 | } 87 | if (onUpdateEvent != null) 88 | { 89 | onUpdateEvent.Invoke(this, fromSource, newAxis, newDelta); 90 | } 91 | } 92 | 93 | private void SteamVR_Behaviour_Vector2_OnChange(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta) 94 | { 95 | if (onChange != null) 96 | { 97 | onChange.Send(this, fromSource, newAxis, newDelta); 98 | } 99 | if (onChangeEvent != null) 100 | { 101 | onChangeEvent.Invoke(this, fromSource, newAxis, newDelta); 102 | } 103 | } 104 | 105 | private void SteamVR_Behaviour_Vector2_OnAxis(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta) 106 | { 107 | if (onAxis != null) 108 | { 109 | onAxis.Send(this, fromSource, newAxis, newDelta); 110 | } 111 | if (onAxisEvent != null) 112 | { 113 | onAxisEvent.Invoke(this, fromSource, newAxis, newDelta); 114 | } 115 | } 116 | 117 | /// 118 | /// Gets the localized name of the device that the action corresponds to. 119 | /// 120 | /// 121 | /// 122 | /// VRInputString_Hand - Which hand the origin is in. E.g. "Left Hand" 123 | /// VRInputString_ControllerType - What kind of controller the user has in that hand.E.g. "Vive Controller" 124 | /// VRInputString_InputSource - What part of that controller is the origin. E.g. "Trackpad" 125 | /// VRInputString_All - All of the above. E.g. "Left Hand Vive Controller Trackpad" 126 | /// 127 | /// 128 | public string GetLocalizedName(params EVRInputStringBits[] localizedParts) 129 | { 130 | if (vector2Action != null) 131 | return vector2Action.GetLocalizedOriginPart(inputSource, localizedParts); 132 | return null; 133 | } 134 | 135 | public delegate void AxisHandler(SteamVR_Behaviour_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta); 136 | public delegate void ChangeHandler(SteamVR_Behaviour_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta); 137 | public delegate void UpdateHandler(SteamVR_Behaviour_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 newAxis, Vector2 newDelta); 138 | } 139 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_Frustum.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Generates a mesh based on field of view. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | // [ExecuteInEditMode, RequireComponent(typeof(MeshRenderer), typeof(MeshFilter))] 12 | public class SteamVR_Frustum : MonoBehaviour 13 | { 14 | static SteamVR_Frustum() 15 | { 16 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 17 | } 18 | 19 | public SteamVR_TrackedObject.EIndex index; 20 | 21 | public float fovLeft = 45, fovRight = 45, fovTop = 45, fovBottom = 45, nearZ = 0.5f, farZ = 2.5f; 22 | 23 | public void UpdateModel() 24 | { 25 | fovLeft = Mathf.Clamp(fovLeft, 1, 89); 26 | fovRight = Mathf.Clamp(fovRight, 1, 89); 27 | fovTop = Mathf.Clamp(fovTop, 1, 89); 28 | fovBottom = Mathf.Clamp(fovBottom, 1, 89); 29 | farZ = Mathf.Max(farZ, nearZ + 0.01f); 30 | nearZ = Mathf.Clamp(nearZ, 0.01f, farZ - 0.01f); 31 | 32 | var lsin = Mathf.Sin(-fovLeft * Mathf.Deg2Rad); 33 | var rsin = Mathf.Sin(fovRight * Mathf.Deg2Rad); 34 | var tsin = Mathf.Sin(fovTop * Mathf.Deg2Rad); 35 | var bsin = Mathf.Sin(-fovBottom * Mathf.Deg2Rad); 36 | 37 | var lcos = Mathf.Cos(-fovLeft * Mathf.Deg2Rad); 38 | var rcos = Mathf.Cos(fovRight * Mathf.Deg2Rad); 39 | var tcos = Mathf.Cos(fovTop * Mathf.Deg2Rad); 40 | var bcos = Mathf.Cos(-fovBottom * Mathf.Deg2Rad); 41 | 42 | var corners = new Vector3[] { 43 | new Vector3(lsin * nearZ / lcos, tsin * nearZ / tcos, nearZ), //tln 44 | new Vector3(rsin * nearZ / rcos, tsin * nearZ / tcos, nearZ), //trn 45 | new Vector3(rsin * nearZ / rcos, bsin * nearZ / bcos, nearZ), //brn 46 | new Vector3(lsin * nearZ / lcos, bsin * nearZ / bcos, nearZ), //bln 47 | new Vector3(lsin * farZ / lcos, tsin * farZ / tcos, farZ ), //tlf 48 | new Vector3(rsin * farZ / rcos, tsin * farZ / tcos, farZ ), //trf 49 | new Vector3(rsin * farZ / rcos, bsin * farZ / bcos, farZ ), //brf 50 | new Vector3(lsin * farZ / lcos, bsin * farZ / bcos, farZ ), //blf 51 | }; 52 | 53 | var triangles = new int[] { 54 | // 0, 1, 2, 0, 2, 3, // near 55 | // 0, 2, 1, 0, 3, 2, // near 56 | // 4, 5, 6, 4, 6, 7, // far 57 | // 4, 6, 5, 4, 7, 6, // far 58 | 0, 4, 7, 0, 7, 3, // left 59 | 0, 7, 4, 0, 3, 7, // left 60 | 1, 5, 6, 1, 6, 2, // right 61 | 1, 6, 5, 1, 2, 6, // right 62 | 0, 4, 5, 0, 5, 1, // top 63 | 0, 5, 4, 0, 1, 5, // top 64 | 2, 3, 7, 2, 7, 6, // bottom 65 | 2, 7, 3, 2, 6, 7, // bottom 66 | }; 67 | 68 | int j = 0; 69 | var vertices = new Vector3[triangles.Length]; 70 | var normals = new Vector3[triangles.Length]; 71 | for (int i = 0; i < triangles.Length / 3; i++) 72 | { 73 | var a = corners[triangles[i * 3 + 0]]; 74 | var b = corners[triangles[i * 3 + 1]]; 75 | var c = corners[triangles[i * 3 + 2]]; 76 | var n = Vector3.Cross(b - a, c - a).normalized; 77 | normals[i * 3 + 0] = n; 78 | normals[i * 3 + 1] = n; 79 | normals[i * 3 + 2] = n; 80 | vertices[i * 3 + 0] = a; 81 | vertices[i * 3 + 1] = b; 82 | vertices[i * 3 + 2] = c; 83 | triangles[i * 3 + 0] = j++; 84 | triangles[i * 3 + 1] = j++; 85 | triangles[i * 3 + 2] = j++; 86 | } 87 | 88 | var mesh = new Mesh(); 89 | mesh.vertices = vertices; 90 | mesh.normals = normals; 91 | mesh.triangles = triangles; 92 | 93 | GetComponent().mesh = mesh; 94 | } 95 | 96 | private void OnDeviceConnected(int i, bool connected) 97 | { 98 | if (i != (int)index) 99 | return; 100 | 101 | GetComponent().mesh = null; 102 | 103 | if (connected) 104 | { 105 | var system = OpenVR.System; 106 | if (system != null && system.GetTrackedDeviceClass((uint)i) == ETrackedDeviceClass.TrackingReference) 107 | { 108 | var error = ETrackedPropertyError.TrackedProp_Success; 109 | var result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_FieldOfViewLeftDegrees_Float, ref error); 110 | if (error == ETrackedPropertyError.TrackedProp_Success) 111 | fovLeft = result; 112 | 113 | result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_FieldOfViewRightDegrees_Float, ref error); 114 | if (error == ETrackedPropertyError.TrackedProp_Success) 115 | fovRight = result; 116 | 117 | result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_FieldOfViewTopDegrees_Float, ref error); 118 | if (error == ETrackedPropertyError.TrackedProp_Success) 119 | fovTop = result; 120 | 121 | result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_FieldOfViewBottomDegrees_Float, ref error); 122 | if (error == ETrackedPropertyError.TrackedProp_Success) 123 | fovBottom = result; 124 | 125 | result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_TrackingRangeMinimumMeters_Float, ref error); 126 | if (error == ETrackedPropertyError.TrackedProp_Success) 127 | nearZ = result; 128 | 129 | result = system.GetFloatTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_TrackingRangeMaximumMeters_Float, ref error); 130 | if (error == ETrackedPropertyError.TrackedProp_Success) 131 | farZ = result; 132 | 133 | UpdateModel(); 134 | } 135 | } 136 | } 137 | 138 | void OnEnable() 139 | { 140 | GetComponent().mesh = null; 141 | SteamVR_Events.DeviceConnected.Listen(OnDeviceConnected); 142 | } 143 | 144 | void OnDisable() 145 | { 146 | SteamVR_Events.DeviceConnected.Remove(OnDeviceConnected); 147 | GetComponent().mesh = null; 148 | } 149 | 150 | #if UNITY_EDITOR 151 | void Update() 152 | { 153 | if (!Application.isPlaying) 154 | UpdateModel(); 155 | } 156 | #endif 157 | } 158 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_RingBuffer.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | 3 | using UnityEngine; 4 | 5 | namespace Valve.VR 6 | { 7 | public class SteamVR_RingBuffer 8 | { 9 | protected T[] buffer; 10 | protected int currentIndex; 11 | protected T lastElement; 12 | 13 | public SteamVR_RingBuffer(int size) 14 | { 15 | buffer = new T[size]; 16 | currentIndex = 0; 17 | } 18 | 19 | public void Add(T newElement) 20 | { 21 | buffer[currentIndex] = newElement; 22 | 23 | StepForward(); 24 | } 25 | 26 | public virtual void StepForward() 27 | { 28 | lastElement = buffer[currentIndex]; 29 | 30 | currentIndex++; 31 | if (currentIndex >= buffer.Length) 32 | currentIndex = 0; 33 | 34 | cleared = false; 35 | } 36 | 37 | public virtual T GetAtIndex(int atIndex) 38 | { 39 | if (atIndex < 0) 40 | atIndex += buffer.Length; 41 | 42 | return buffer[atIndex]; 43 | } 44 | 45 | public virtual T GetLast() 46 | { 47 | return lastElement; 48 | } 49 | 50 | public virtual int GetLastIndex() 51 | { 52 | int lastIndex = currentIndex - 1; 53 | if (lastIndex < 0) 54 | lastIndex += buffer.Length; 55 | 56 | return lastIndex; 57 | } 58 | 59 | private bool cleared = false; 60 | public void Clear() 61 | { 62 | if (cleared == true) 63 | return; 64 | 65 | if (buffer == null) 66 | return; 67 | 68 | for (int index = 0; index < buffer.Length; index++) 69 | { 70 | buffer[index] = default(T); 71 | } 72 | 73 | lastElement = default(T); 74 | 75 | currentIndex = 0; 76 | 77 | cleared = true; 78 | } 79 | } 80 | 81 | public class SteamVR_HistoryBuffer : SteamVR_RingBuffer 82 | { 83 | public SteamVR_HistoryBuffer(int size) : base(size) 84 | { 85 | 86 | } 87 | 88 | public void Update(Vector3 position, Quaternion rotation, Vector3 velocity, Vector3 angularVelocity) 89 | { 90 | if (buffer[currentIndex] == null) 91 | buffer[currentIndex] = new SteamVR_HistoryStep(); 92 | 93 | buffer[currentIndex].position = position; 94 | buffer[currentIndex].rotation = rotation; 95 | buffer[currentIndex].velocity = velocity; 96 | buffer[currentIndex].angularVelocity = angularVelocity; 97 | buffer[currentIndex].timeInTicks = System.DateTime.Now.Ticks; 98 | 99 | StepForward(); 100 | } 101 | 102 | public float GetVelocityMagnitudeTrend(int toIndex = -1, int fromIndex = -1) 103 | { 104 | if (toIndex == -1) 105 | toIndex = currentIndex - 1; 106 | 107 | if (toIndex < 0) 108 | toIndex += buffer.Length; 109 | 110 | if (fromIndex == -1) 111 | fromIndex = toIndex - 1; 112 | 113 | if (fromIndex < 0) 114 | fromIndex += buffer.Length; 115 | 116 | SteamVR_HistoryStep toStep = buffer[toIndex]; 117 | SteamVR_HistoryStep fromStep = buffer[fromIndex]; 118 | 119 | if (IsValid(toStep) && IsValid(fromStep)) 120 | { 121 | return toStep.velocity.sqrMagnitude - fromStep.velocity.sqrMagnitude; 122 | } 123 | 124 | return 0; 125 | } 126 | 127 | public bool IsValid(SteamVR_HistoryStep step) 128 | { 129 | return step != null && step.timeInTicks != -1; 130 | } 131 | 132 | public int GetTopVelocity(int forFrames, int addFrames = 0) 133 | { 134 | int topFrame = currentIndex; 135 | float topVelocitySqr = 0; 136 | 137 | int currentFrame = currentIndex; 138 | 139 | while (forFrames > 0) 140 | { 141 | forFrames--; 142 | currentFrame--; 143 | 144 | if (currentFrame < 0) 145 | currentFrame = buffer.Length - 1; 146 | 147 | SteamVR_HistoryStep currentStep = buffer[currentFrame]; 148 | 149 | if (IsValid(currentStep) == false) 150 | break; 151 | 152 | float currentSqr = buffer[currentFrame].velocity.sqrMagnitude; 153 | if (currentSqr > topVelocitySqr) 154 | { 155 | topFrame = currentFrame; 156 | topVelocitySqr = currentSqr; 157 | } 158 | } 159 | 160 | topFrame += addFrames; 161 | 162 | if (topFrame >= buffer.Length) 163 | topFrame -= buffer.Length; 164 | 165 | return topFrame; 166 | } 167 | 168 | public void GetAverageVelocities(out Vector3 velocity, out Vector3 angularVelocity, int forFrames, int startFrame = -1) 169 | { 170 | velocity = Vector3.zero; 171 | angularVelocity = Vector3.zero; 172 | 173 | if (startFrame == -1) 174 | startFrame = currentIndex - 1; 175 | 176 | if (startFrame < 0) 177 | startFrame = buffer.Length - 1; 178 | 179 | int endFrame = startFrame - forFrames; 180 | 181 | if (endFrame < 0) 182 | endFrame += buffer.Length; 183 | 184 | Vector3 totalVelocity = Vector3.zero; 185 | Vector3 totalAngularVelocity = Vector3.zero; 186 | float totalFrames = 0; 187 | int currentFrame = startFrame; 188 | while (forFrames > 0) 189 | { 190 | forFrames--; 191 | currentFrame--; 192 | 193 | if (currentFrame < 0) 194 | currentFrame = buffer.Length - 1; 195 | 196 | SteamVR_HistoryStep currentStep = buffer[currentFrame]; 197 | 198 | if (IsValid(currentStep) == false) 199 | break; 200 | 201 | totalFrames++; 202 | 203 | totalVelocity += currentStep.velocity; 204 | totalAngularVelocity += currentStep.angularVelocity; 205 | } 206 | 207 | velocity = totalVelocity / totalFrames; 208 | angularVelocity = totalAngularVelocity / totalFrames; 209 | } 210 | } 211 | 212 | public class SteamVR_HistoryStep 213 | { 214 | public Vector3 position; 215 | public Quaternion rotation; 216 | 217 | public Vector3 velocity; 218 | 219 | public Vector3 angularVelocity; 220 | 221 | public long timeInTicks = -1; 222 | } 223 | } -------------------------------------------------------------------------------- /SteamVRLib_Valve.VR/SteamVR/Scripts/SteamVR_Overlay.cs: -------------------------------------------------------------------------------- 1 | //======= Copyright (c) Valve Corporation, All rights reserved. =============== 2 | // 3 | // Purpose: Displays 2d content on a large virtual screen. 4 | // 5 | //============================================================================= 6 | 7 | using UnityEngine; 8 | 9 | namespace Valve.VR 10 | { 11 | public class SteamVR_Overlay : MonoBehaviour 12 | { 13 | static SteamVR_Overlay() 14 | { 15 | Il2CppInterop.Runtime.Injection.ClassInjector.RegisterTypeInIl2Cpp(); 16 | } 17 | 18 | public Texture texture; 19 | 20 | // [Tooltip("Size of overlay view.")] 21 | public float scale = 3.0f; 22 | 23 | // [Tooltip("Distance from surface.")] 24 | public float distance = 1.25f; 25 | 26 | // [Tooltip("Opacity"), Range(0.0f, 1.0f)] 27 | public float alpha = 1.0f; 28 | 29 | public Vector4 uvOffset = new Vector4(0, 0, 1, 1); 30 | public Vector2 mouseScale = new Vector2(1, 1); 31 | 32 | public VROverlayInputMethod inputMethod = VROverlayInputMethod.None; 33 | 34 | static public SteamVR_Overlay instance { get; private set; } 35 | 36 | static public string key { get { return "unity:" + Application.companyName + "." + Application.productName; } } 37 | 38 | private ulong handle = OpenVR.k_ulOverlayHandleInvalid; 39 | 40 | void OnEnable() 41 | { 42 | var overlay = OpenVR.Overlay; 43 | if (overlay != null) 44 | { 45 | var error = overlay.CreateOverlay(key, gameObject.name, ref handle); 46 | if (error != EVROverlayError.None) 47 | { 48 | Debug.Log("[SteamVR] " + overlay.GetOverlayErrorNameFromEnum(error)); 49 | enabled = false; 50 | return; 51 | } 52 | } 53 | 54 | SteamVR_Overlay.instance = this; 55 | } 56 | 57 | void OnDisable() 58 | { 59 | if (handle != OpenVR.k_ulOverlayHandleInvalid) 60 | { 61 | var overlay = OpenVR.Overlay; 62 | if (overlay != null) 63 | { 64 | overlay.DestroyOverlay(handle); 65 | } 66 | 67 | handle = OpenVR.k_ulOverlayHandleInvalid; 68 | } 69 | 70 | SteamVR_Overlay.instance = null; 71 | } 72 | 73 | public void UpdateOverlay() 74 | { 75 | var overlay = OpenVR.Overlay; 76 | if (overlay == null) 77 | return; 78 | 79 | if (texture != null) 80 | { 81 | var error = overlay.ShowOverlay(handle); 82 | if (error == EVROverlayError.InvalidHandle || error == EVROverlayError.UnknownOverlay) 83 | { 84 | if (overlay.FindOverlay(key, ref handle) != EVROverlayError.None) 85 | return; 86 | } 87 | 88 | var tex = new Texture_t(); 89 | tex.handle = texture.GetNativeTexturePtr(); 90 | tex.eType = SteamVR.instance.textureType; 91 | tex.eColorSpace = EColorSpace.Auto; 92 | overlay.SetOverlayTexture(handle, ref tex); 93 | 94 | overlay.SetOverlayAlpha(handle, alpha); 95 | overlay.SetOverlayWidthInMeters(handle, scale); 96 | 97 | var textureBounds = new VRTextureBounds_t(); 98 | textureBounds.uMin = (0 + uvOffset.x) * uvOffset.z; 99 | textureBounds.vMin = (1 + uvOffset.y) * uvOffset.w; 100 | textureBounds.uMax = (1 + uvOffset.x) * uvOffset.z; 101 | textureBounds.vMax = (0 + uvOffset.y) * uvOffset.w; 102 | overlay.SetOverlayTextureBounds(handle, ref textureBounds); 103 | 104 | var vecMouseScale = new HmdVector2_t(); 105 | vecMouseScale.v0 = mouseScale.x; 106 | vecMouseScale.v1 = mouseScale.y; 107 | overlay.SetOverlayMouseScale(handle, ref vecMouseScale); 108 | 109 | var vrcam = SteamVR_Render.Top(); 110 | if (vrcam != null && vrcam.origin != null) 111 | { 112 | var offset = new SteamVR_Utils.RigidTransform(vrcam.origin, transform); 113 | offset.pos.x /= vrcam.origin.localScale.x; 114 | offset.pos.y /= vrcam.origin.localScale.y; 115 | offset.pos.z /= vrcam.origin.localScale.z; 116 | 117 | offset.pos.z += distance; 118 | 119 | var t = offset.ToHmdMatrix34(); 120 | overlay.SetOverlayTransformAbsolute(handle, SteamVR.settings.trackingSpace, ref t); 121 | } 122 | 123 | overlay.SetOverlayInputMethod(handle, inputMethod); 124 | } 125 | else 126 | { 127 | overlay.HideOverlay(handle); 128 | } 129 | } 130 | 131 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 132 | public bool PollNextEvent(ref VREvent_t pEvent) 133 | { 134 | var overlay = OpenVR.Overlay; 135 | if (overlay == null) 136 | return false; 137 | 138 | var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(Valve.VR.VREvent_t)); 139 | return overlay.PollNextOverlayEvent(handle, ref pEvent, size); 140 | } 141 | 142 | public struct IntersectionResults 143 | { 144 | public Vector3 point; 145 | public Vector3 normal; 146 | public Vector2 UVs; 147 | public float distance; 148 | } 149 | 150 | [Il2CppInterop.Runtime.Attributes.HideFromIl2Cpp] 151 | public bool ComputeIntersection(Vector3 source, Vector3 direction, ref IntersectionResults results) 152 | { 153 | var overlay = OpenVR.Overlay; 154 | if (overlay == null) 155 | return false; 156 | 157 | var input = new VROverlayIntersectionParams_t(); 158 | input.eOrigin = SteamVR.settings.trackingSpace; 159 | input.vSource.v0 = source.x; 160 | input.vSource.v1 = source.y; 161 | input.vSource.v2 = -source.z; 162 | input.vDirection.v0 = direction.x; 163 | input.vDirection.v1 = direction.y; 164 | input.vDirection.v2 = -direction.z; 165 | 166 | var output = new VROverlayIntersectionResults_t(); 167 | if (!overlay.ComputeOverlayIntersection(handle, ref input, ref output)) 168 | return false; 169 | 170 | results.point = new Vector3(output.vPoint.v0, output.vPoint.v1, -output.vPoint.v2); 171 | results.normal = new Vector3(output.vNormal.v0, output.vNormal.v1, -output.vNormal.v2); 172 | results.UVs = new Vector2(output.vUVs.v0, output.vUVs.v1); 173 | results.distance = output.fDistance; 174 | return true; 175 | } 176 | } 177 | } --------------------------------------------------------------------------------