diff --git a/Scripts/Core/EditorXRInterfacesModule.cs b/Scripts/Core/EditorXRInterfacesModule.cs index 86d95e5d7..23d552e47 100644 --- a/Scripts/Core/EditorXRInterfacesModule.cs +++ b/Scripts/Core/EditorXRInterfacesModule.cs @@ -13,7 +13,7 @@ class EditorXRInterfacesModule : IInitializableModule event Action connectInterfaces; event Action disconnectInterfaces; - public int initializationOrder { get { return -1; } } + public int initializationOrder { get { return -4; } } public int shutdownOrder { get { return 0; } } public void LoadModule() diff --git a/Scripts/Core/EditorXRViewerModule.cs b/Scripts/Core/EditorXRViewerModule.cs index bdf2cbe02..f0f9d3e21 100644 --- a/Scripts/Core/EditorXRViewerModule.cs +++ b/Scripts/Core/EditorXRViewerModule.cs @@ -71,6 +71,7 @@ public float cameraRigScale PlayerBody m_PlayerBody; GameObject m_PlayerFloor; + bool m_Initialized; float m_OriginalNearClipPlane; float m_OriginalFarClipPlane; readonly List m_VRPlayerObjects = new List(); @@ -80,7 +81,7 @@ public float cameraRigScale SpatialHashModule m_SpatialHashModule; IntersectionModule m_IntersectionModule; - public int initializationOrder { get { return 0; } } + public int initializationOrder { get { return -2; } } public int shutdownOrder { get { return 0; } } internal IPreviewCamera customPreviewCamera { get; private set; } @@ -117,11 +118,7 @@ public void LoadModule() VRView.hmdStatusChange += OnHMDStatusChange; #endif - preserveCameraRig = true; - Shader.SetGlobalFloat(k_WorldScaleProperty, 1); - - preserveCameraRig = EditorVR.preserveLayout; } public void UnloadModule() @@ -129,19 +126,6 @@ public void UnloadModule() #if UNITY_EDITOR VRView.hmdStatusChange -= OnHMDStatusChange; #endif - - var cameraRig = CameraUtils.GetCameraRig(); - if (cameraRig) - cameraRig.transform.parent = null; - - if (m_PlayerBody) - UnityObjectUtils.Destroy(m_PlayerBody.gameObject); - - if (m_PlayerFloor) - UnityObjectUtils.Destroy(m_PlayerFloor); - - if (customPreviewCamera != null && customPreviewCamera as MonoBehaviour != null) - UnityObjectUtils.Destroy(((MonoBehaviour)customPreviewCamera).gameObject); } public void ConnectInterface(object target, object userData = null) @@ -252,6 +236,7 @@ internal void UpdateCamera() internal void AddPlayerFloor() { m_PlayerFloor = EditorXRUtils.Instantiate(m_PlayerFloorPrefab, CameraUtils.GetCameraRig().transform, false); + m_VRPlayerObjects.Add(m_PlayerFloor); } internal void AddPlayerModel() @@ -380,27 +365,46 @@ void SetViewerScale(float scale) { var camera = CameraUtils.GetMainCamera(); CameraUtils.GetCameraRig().localScale = Vector3.one * scale; - camera.nearClipPlane = m_OriginalNearClipPlane * scale; - camera.farClipPlane = m_OriginalFarClipPlane * scale; Shader.SetGlobalFloat(k_WorldScaleProperty, 1f / scale); + if (m_Initialized) + { + camera.nearClipPlane = m_OriginalNearClipPlane * scale; + camera.farClipPlane = m_OriginalFarClipPlane * scale; + } } public void Initialize() { + preserveCameraRig = EditorVR.preserveLayout; + m_VRPlayerObjects.Clear(); InitializeCamera(); AddPlayerModel(); AddPlayerFloor(); + m_Initialized = true; } public void Shutdown() { + m_Initialized = true; + m_OriginalNearClipPlane = 0; + m_OriginalFarClipPlane = 0; + hmdReady = false; + preserveCameraRig = false; + foreach (var playerObject in m_VRPlayerObjects) { UnityObjectUtils.Destroy(playerObject); } - UnityObjectUtils.Destroy(m_PlayerFloor); + m_VRPlayerObjects.Clear(); + + var cameraRig = CameraUtils.GetCameraRig(); + if (cameraRig) + cameraRig.transform.parent = null; + + if (customPreviewCamera != null && customPreviewCamera as MonoBehaviour != null) + UnityObjectUtils.Destroy(((MonoBehaviour)customPreviewCamera).gameObject); } public void OnBehaviorAwake() { } diff --git a/Scripts/Modules/SerializedPreferencesModule.cs b/Scripts/Modules/SerializedPreferencesModule.cs index 9dd815b51..a14fc0866 100644 --- a/Scripts/Modules/SerializedPreferencesModule.cs +++ b/Scripts/Modules/SerializedPreferencesModule.cs @@ -86,7 +86,7 @@ internal static string serializedPreferences set { EditorPrefs.SetString(SerializedPreferencesKey, value); } } - public int initializationOrder { get { return -2; } } + public int initializationOrder { get { return -1; } } public int shutdownOrder { get { return 1; } } public void Initialize() diff --git a/Scripts/Modules/SpatialHashModule.cs b/Scripts/Modules/SpatialHashModule.cs index 7ce411720..b80b1dd2d 100644 --- a/Scripts/Modules/SpatialHashModule.cs +++ b/Scripts/Modules/SpatialHashModule.cs @@ -17,7 +17,7 @@ sealed class SpatialHashModule : MonoBehaviour, IInitializableModule public Func shouldExcludeObject { private get; set; } - public int initializationOrder { get { return -1; } } + public int initializationOrder { get { return -3; } } public int shutdownOrder { get { return 0; } } public void LoadModule()