diff --git a/DebugProjects/Unity2020.3/Assets/XR/Settings/Web XR Settings.asset b/DebugProjects/Unity2020.3/Assets/XR/Settings/Web XR Settings.asset index 99e66386..ee51f0be 100644 --- a/DebugProjects/Unity2020.3/Assets/XR/Settings/Web XR Settings.asset +++ b/DebugProjects/Unity2020.3/Assets/XR/Settings/Web XR Settings.asset @@ -16,3 +16,8 @@ MonoBehaviour: VROptionalFeatures: 2 ARRequiredReferenceSpace: 2 AROptionalFeatures: -1 + UseFramebufferScaleFactor: 0 + UseNativeResolution: 0 + FramebufferScaleFactor: 1 + AutoLoadWebXRManager: 1 + AutoLoadWebXRInputSystem: 0 diff --git a/DebugProjects/Unity2020.3/Packages/packages-lock.json b/DebugProjects/Unity2020.3/Packages/packages-lock.json index 8d1874af..866aa5d2 100644 --- a/DebugProjects/Unity2020.3/Packages/packages-lock.json +++ b/DebugProjects/Unity2020.3/Packages/packages-lock.json @@ -23,7 +23,7 @@ "depth": 0, "source": "embedded", "dependencies": { - "com.de-panther.webxr": "0.20.0" + "com.de-panther.webxr": "0.20.1-preview" } }, "com.unity.burst": { diff --git a/MainProject/Assets/XR/Settings/Web XR Settings.asset b/MainProject/Assets/XR/Settings/Web XR Settings.asset index 43fb4eab..eb4ab04d 100644 --- a/MainProject/Assets/XR/Settings/Web XR Settings.asset +++ b/MainProject/Assets/XR/Settings/Web XR Settings.asset @@ -19,3 +19,5 @@ MonoBehaviour: UseFramebufferScaleFactor: 0 UseNativeResolution: 0 FramebufferScaleFactor: 1 + AutoLoadWebXRManager: 1 + AutoLoadWebXRInputSystem: 1 diff --git a/MainProject/Packages/packages-lock.json b/MainProject/Packages/packages-lock.json index 8c6c29df..16ef75e3 100644 --- a/MainProject/Packages/packages-lock.json +++ b/MainProject/Packages/packages-lock.json @@ -23,7 +23,7 @@ "depth": 0, "source": "embedded", "dependencies": { - "com.de-panther.webxr": "0.20.0" + "com.de-panther.webxr": "0.20.1-preview" } }, "com.unity.burst": { diff --git a/MainProject/ProjectSettings/GraphicsSettings.asset b/MainProject/ProjectSettings/GraphicsSettings.asset index 378d3c06..3b3bf3bd 100644 --- a/MainProject/ProjectSettings/GraphicsSettings.asset +++ b/MainProject/ProjectSettings/GraphicsSettings.asset @@ -29,8 +29,7 @@ GraphicsSettings: m_AlwaysIncludedShaders: - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0} - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0} - - {fileID: -6465566751694194690, guid: 90c26dfde11bf4ff69ef936c6e6b1ed1, type: 3} - - {fileID: -6465566751694194690, guid: ba6d401c74b2c4f96af7edf0fe32241e, type: 3} + - {fileID: -6465566751694194690, guid: b9d29dfa1474148e792ac720cbd45122, type: 3} m_PreloadedShaders: [] m_PreloadShadersBatchTimeLimit: -1 m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, diff --git a/Packages/webxr-interactions/CHANGELOG.md b/Packages/webxr-interactions/CHANGELOG.md index 469d6959..dce77fad 100644 --- a/Packages/webxr-interactions/CHANGELOG.md +++ b/Packages/webxr-interactions/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- An option to auto-load WebXRInputSystem on start in WebXRSettings. + ### Changed - Minimum WebXR Input Profiles Loader version 0.6.0. diff --git a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs index d53048ea..29108910 100644 --- a/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs +++ b/Packages/webxr-interactions/Runtime/InputSystem/WebXRInputSystem.cs @@ -39,6 +39,7 @@ public static string[] GetRightProfiles() } #if UNITY_INPUT_SYSTEM_1_4_4_OR_NEWER private static bool initialized = false; + private static int instances = 0; private static WebXRController left = null; private static WebXRController right = null; private static bool hasLeftProfiles = false; @@ -49,6 +50,18 @@ public static string[] GetRightProfiles() private static XRHandProviderUtility.SubsystemUpdater subsystemUpdater; #endif + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] + private static void TryAutoLoad() + { + WebXRSettings settings = WebXRSettings.GetSettings(); + if (settings?.AutoLoadWebXRInputSystem == true) + { + var webxrInputSystem = new GameObject("WebXRInputSystem"); + webxrInputSystem.AddComponent(); + DontDestroyOnLoad(webxrInputSystem); + } + } + private void Awake() { if (initialized) @@ -77,6 +90,11 @@ private void Awake() private void OnEnable() { + instances++; + if (instances > 1) + { + return; + } unsafe { InputSystem.onDeviceCommand += HandleOnDeviceCommand; @@ -92,6 +110,11 @@ private void OnEnable() private void OnDisable() { + instances--; + if (instances > 0) + { + return; + } unsafe { InputSystem.onDeviceCommand -= HandleOnDeviceCommand; @@ -109,6 +132,10 @@ private void OnDisable() #if XR_HANDS_1_1_OR_NEWER private void OnDestroy() { + if (instances > 0) + { + return; + } if (MetaAimHand.left != null && MetaAimHand.left.added) { InputSystem.RemoveDevice(MetaAimHand.left); diff --git a/Packages/webxr-interactions/Runtime/Prefabs/WebXRCameraSet.prefab b/Packages/webxr-interactions/Runtime/Prefabs/WebXRCameraSet.prefab index be254396..af272d6a 100644 --- a/Packages/webxr-interactions/Runtime/Prefabs/WebXRCameraSet.prefab +++ b/Packages/webxr-interactions/Runtime/Prefabs/WebXRCameraSet.prefab @@ -9,7 +9,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 4545079059221816} - - component: {fileID: 114038308936181916} m_Layer: 0 m_Name: WebXRCameraSet m_TagString: Untagged @@ -34,18 +33,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114038308936181916 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1611361787474004} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 519f6ee6510174b44bbe9a8a2d3b6a6a, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1799026754646168 GameObject: m_ObjectHideFlags: 0 @@ -108,6 +95,7 @@ FixedJoint: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1799026754646168} m_ConnectedBody: {fileID: 0} + m_ConnectedArticulationBody: {fileID: 0} m_BreakForce: Infinity m_BreakTorque: Infinity m_EnableCollision: 0 @@ -144,8 +132,7 @@ MonoBehaviour: animationStateName: controllerVisuals: - {fileID: 3858442981242374931} - handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, - type: 3} + handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, type: 3} useCollidersForHandJoints: 1 useInputProfile: 1 inputProfileObject: {fileID: 1611361787474004} @@ -363,6 +350,7 @@ FixedJoint: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1986733487743170} m_ConnectedBody: {fileID: 0} + m_ConnectedArticulationBody: {fileID: 0} m_BreakForce: Infinity m_BreakTorque: Infinity m_EnableCollision: 0 @@ -399,8 +387,7 @@ MonoBehaviour: animationStateName: controllerVisuals: - {fileID: 2954843634523120171} - handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, - type: 3} + handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, type: 3} useCollidersForHandJoints: 1 useInputProfile: 1 inputProfileObject: {fileID: 1611361787474004} @@ -569,6 +556,7 @@ MeshRenderer: m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 2 + m_RayTraceProcedural: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -593,6 +581,7 @@ MeshRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} --- !u!65 &4365337428889893541 BoxCollider: m_ObjectHideFlags: 0 @@ -692,6 +681,7 @@ MeshRenderer: m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 2 + m_RayTraceProcedural: 0 m_RenderingLayerMask: 1 m_RendererPriority: 0 m_Materials: @@ -716,6 +706,7 @@ MeshRenderer: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} --- !u!65 &2314441812177900445 BoxCollider: m_ObjectHideFlags: 0 diff --git a/Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab b/Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab index a5cb62d6..9ecb8aac 100644 --- a/Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab +++ b/Packages/webxr-interactions/Samples~/Desert/Prefabs/WebXRCameraSet.prefab @@ -138,6 +138,7 @@ SkinnedMeshRenderer: m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 0 + m_RayTraceProcedural: 0 m_RenderingLayerMask: 4294967295 m_RendererPriority: 0 m_Materials: @@ -744,7 +745,6 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 4545079059221816} - - component: {fileID: 114038308936181916} m_Layer: 0 m_Name: WebXRCameraSet m_TagString: Untagged @@ -769,18 +769,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &114038308936181916 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1611361787474004} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 519f6ee6510174b44bbe9a8a2d3b6a6a, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1644691530447244 GameObject: m_ObjectHideFlags: 0 @@ -950,6 +938,7 @@ SkinnedMeshRenderer: m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 m_RayTracingMode: 0 + m_RayTraceProcedural: 0 m_RenderingLayerMask: 4294967295 m_RendererPriority: 0 m_Materials: @@ -1141,6 +1130,7 @@ FixedJoint: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1799026754646168} m_ConnectedBody: {fileID: 0} + m_ConnectedArticulationBody: {fileID: 0} m_BreakForce: Infinity m_BreakTorque: Infinity m_EnableCollision: 0 @@ -1197,8 +1187,7 @@ MonoBehaviour: controllerVisuals: - {fileID: 1136128897566686} - {fileID: 1664295426898042} - handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, - type: 3} + handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, type: 3} useCollidersForHandJoints: 1 useInputProfile: 1 inputProfileObject: {fileID: 1611361787474004} @@ -1663,6 +1652,7 @@ FixedJoint: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1986733487743170} m_ConnectedBody: {fileID: 0} + m_ConnectedArticulationBody: {fileID: 0} m_BreakForce: Infinity m_BreakTorque: Infinity m_EnableCollision: 0 @@ -1719,8 +1709,7 @@ MonoBehaviour: controllerVisuals: - {fileID: 1644997114004198} - {fileID: 1091283458777958} - handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, - type: 3} + handJointPrefab: {fileID: 8513787482403080262, guid: 67541c9d1fd5e2c4798986ee73c07923, type: 3} useCollidersForHandJoints: 1 useInputProfile: 1 inputProfileObject: {fileID: 1611361787474004} diff --git a/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Interaction WebXR Hands Setup.prefab b/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Interaction WebXR Hands Setup.prefab index 814d9ab0..cb094df1 100644 --- a/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Interaction WebXR Hands Setup.prefab +++ b/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Interaction WebXR Hands Setup.prefab @@ -32,7 +32,6 @@ Transform: - {fileID: 4763085287912399982} - {fileID: 4763085286836561809} - {fileID: 4763085287379932445} - - {fileID: 2735015572710088185} - {fileID: 104277457138784657} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -224,50 +223,6 @@ MonoBehaviour: m_ActionAssets: - {fileID: -944628639613478452, guid: c348712bda248c246b8c49b3db54643f, type: 3} - {fileID: -944628639613478452, guid: 256061f5afc1f4c49bfcb9ca2bc787e1, type: 3} ---- !u!1 &6691460237591051992 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2735015572710088185} - - component: {fileID: 635145867105466161} - m_Layer: 0 - m_Name: WebXRInputSystem - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2735015572710088185 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6691460237591051992} - serializedVersion: 2 - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 5773256366622995465} - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &635145867105466161 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 6691460237591051992} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 30257f473861cfd4a9269b5bf4020e6c, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1001 &405369273336542956 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Origin (WebXR Rig).prefab b/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Origin (WebXR Rig).prefab index 274f8755..6403b1d9 100644 --- a/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Origin (WebXR Rig).prefab +++ b/Packages/webxr-interactions/Samples~/XRInteractionToolkit/Prefabs/XR Origin (WebXR Rig).prefab @@ -952,7 +952,6 @@ GameObject: - component: {fileID: 6232745470614056095} - component: {fileID: 5826056641483426609} - component: {fileID: 5033801203051696737} - - component: {fileID: 2902162407738710112} m_Layer: 2 m_Name: XR Origin (WebXR Rig) m_TagString: Untagged @@ -1091,18 +1090,6 @@ MonoBehaviour: m_AimAssistRequiredSpeed: 0.25 m_AimAssistPercent: 0.8 m_AimAssistMaxSpeedPercent: 10 ---- !u!114 &2902162407738710112 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1717954561962503725} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 519f6ee6510174b44bbe9a8a2d3b6a6a, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &1787516059220952802 GameObject: m_ObjectHideFlags: 0 diff --git a/Packages/webxr-interactions/package.json b/Packages/webxr-interactions/package.json index 97b0d00a..24d7976c 100644 --- a/Packages/webxr-interactions/package.json +++ b/Packages/webxr-interactions/package.json @@ -30,6 +30,6 @@ } ], "dependencies": { - "com.de-panther.webxr": "0.20.0" + "com.de-panther.webxr": "0.20.1-preview" } } diff --git a/Packages/webxr/CHANGELOG.md b/Packages/webxr/CHANGELOG.md index 0c4c2138..deacb6c6 100644 --- a/Packages/webxr/CHANGELOG.md +++ b/Packages/webxr/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- An option to auto-load WebXRManager on start in WebXRSettings. +- An option to auto-load WebXRInputSystem on start in WebXRSettings. + ## [0.20.0] - 2023-12-18 ### Added - Native XRSubsystem for WebXR Display rendering. diff --git a/Packages/webxr/Runtime/Scripts/WebXRManager.cs b/Packages/webxr/Runtime/Scripts/WebXRManager.cs index 67c45d9b..aa8fb53b 100644 --- a/Packages/webxr/Runtime/Scripts/WebXRManager.cs +++ b/Packages/webxr/Runtime/Scripts/WebXRManager.cs @@ -127,6 +127,18 @@ public void StopViewerHitTest() subsystem?.StopViewerHitTest(); } + [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)] + private static void TryAutoLoad() + { + WebXRSettings settings = WebXRSettings.GetSettings(); + if (settings?.AutoLoadWebXRManager == true) + { + var webXRManager = new GameObject("WebXRManager"); + webXRManager.AddComponent(); + DontDestroyOnLoad(webXRManager); + } + } + protected override void Awake() { base.Awake(); diff --git a/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs b/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs index 6b5159e4..90f83c44 100644 --- a/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs +++ b/Packages/webxr/Runtime/XRPlugin/WebXRLoader.cs @@ -25,25 +25,12 @@ public class WebXRLoader : XRLoaderHelper private static extern void RegisterWebXRPlugin(); #endif - WebXRSettings GetSettings() - { - WebXRSettings settings = null; - // When running in the Unity Editor, we have to load user's customization of configuration data directly from - // EditorBuildSettings. At runtime, we need to grab it from the static instance field instead. -#if UNITY_EDITOR - UnityEditor.EditorBuildSettings.TryGetConfigObject("WebXR.Settings", out settings); -#elif UNITY_WEBGL - settings = WebXRSettings.Instance; -#endif - return settings; - } - public override bool Initialize() { #if UNITY_WEBGL && !UNITY_EDITOR RegisterWebXRPlugin(); #endif - WebXRSettings settings = GetSettings(); + WebXRSettings settings = WebXRSettings.GetSettings(); if (settings != null) { Debug.Log($"Got WebXRSettings"); diff --git a/Packages/webxr/Runtime/XRPlugin/WebXRSettings.cs b/Packages/webxr/Runtime/XRPlugin/WebXRSettings.cs index 734de097..39038153 100644 --- a/Packages/webxr/Runtime/XRPlugin/WebXRSettings.cs +++ b/Packages/webxr/Runtime/XRPlugin/WebXRSettings.cs @@ -43,6 +43,12 @@ The scale factor in which the scene is rendered in. Default is 1.0, the recommended resolution.")] [Range(0.2f,2.0f)] public float FramebufferScaleFactor = 1.0f; + [Tooltip(@"Should WebXRManager be created on start or manually by the developer.")] + public bool AutoLoadWebXRManager = true; + [Tooltip(@"Should WebXRInputSystem be created on start or manually by the developer. +WebXRInputSystem is needed when using Unity Input System and XR Interaction Toolkit. +WebXRInputSystem is part of WebXR Interactions package.")] + public bool AutoLoadWebXRInputSystem = true; string EnumToString(T value) where T : Enum { @@ -85,6 +91,19 @@ public string ToJson() return result; } + public static WebXRSettings GetSettings() + { + WebXRSettings settings = null; + // When running in the Unity Editor, we have to load user's customization of configuration data directly from + // EditorBuildSettings. At runtime, we need to grab it from the static instance field instead. +#if UNITY_EDITOR + UnityEditor.EditorBuildSettings.TryGetConfigObject("WebXR.Settings", out settings); +#elif UNITY_WEBGL + settings = WebXRSettings.Instance; +#endif + return settings; + } + #if !UNITY_EDITOR private static WebXRSettings instance = null; public static WebXRSettings Instance