diff --git a/Runtime/Scripts/Core/Contexts/EditingContextManager.cs b/Runtime/Scripts/Core/Contexts/EditingContextManager.cs index d0e506a4b..5a900ffaa 100644 --- a/Runtime/Scripts/Core/Contexts/EditingContextManager.cs +++ b/Runtime/Scripts/Core/Contexts/EditingContextManager.cs @@ -1,3 +1,8 @@ +// Edit mode support requires legacy VR, which was removed in 2020.1 +#if UNITY_EDITOR && !UNITY_2020_1_OR_NEWER +#define UNITY_EDITORXR_EDIT_MODE_SUPPORT +#endif + using System; using System.Collections.Generic; using System.IO; @@ -10,9 +15,12 @@ using UnityEngine; using UnityEngine.Assertions; using UnityEngine.InputNew; -using UnityEngine.XR; using UnityObject = UnityEngine.Object; +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT +using UnityEngine.XR; +#endif + namespace Unity.EditorXR.Core { #if UNITY_EDITOR @@ -28,8 +36,10 @@ sealed class EditingContextManager : MonoBehaviour internal const string settingsPath = "ProjectSettings/EditingContextManagerSettings.asset"; internal const string userSettingsPath = "Library/EditingContextManagerSettings.asset"; +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT const string k_AutoOpen = "EditorXR.EditingContextManager.AutoOpen"; const string k_LaunchOnExitPlaymode = "EditorXR.EditingContextManager.LaunchOnExitPlaymode"; +#endif IEditingContext m_CurrentContext; @@ -38,7 +48,7 @@ sealed class EditingContextManager : MonoBehaviour static EditingContextManagerSettings s_Settings; static UnityObject s_DefaultContext; -#if UNITY_EDITOR +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT static bool s_AutoOpened; static bool s_UserWasPresent; static bool s_EnableXRFailed; @@ -74,11 +84,6 @@ internal static IEditingContext defaultContext set { settings.defaultContextName = value.name; } } - internal IEditingContext currentContext - { - get { return m_CurrentContext; } - } - static EditingContextManagerSettings settings { get @@ -90,13 +95,18 @@ static EditingContextManagerSettings settings } } + internal IEditingContext currentContext + { + get { return m_CurrentContext; } + } + +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT static bool autoOpen { get { return EditorPrefs.GetBool(k_AutoOpen, true); } set { EditorPrefs.SetBool(k_AutoOpen, value); } } -#if UNITY_EDITOR static EditingContextManager() { VRView.viewEnabled += OnVRViewEnabled; @@ -119,7 +129,7 @@ static void OnVRViewEnabled() static void OnVRViewDisabled() { -#if UNITY_EDITOR +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT s_AutoOpened = false; #endif @@ -131,27 +141,6 @@ static void OnVRViewDisabled() } #if UNITY_EDITOR - [MenuItem("Window/EditorXR %e", false)] - internal static void ShowEditorXR() - { - if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying) - return; - - // Using a utility window improves performance by saving from the overhead of DockArea.OnGUI() - EditorWindow.GetWindow(true, "EditorXR", true); - } - - [MenuItem("Window/EditorXR %e", true)] - static bool ShouldShowEditorXR() - { - if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying) - return false; - -#pragma warning disable 618 - return PlayerSettings.GetVirtualRealitySupported(BuildTargetGroup.Standalone); -#pragma warning restore 618 - } - [SettingsProvider] static SettingsProvider CreateSettingsProvider() { @@ -166,6 +155,7 @@ static SettingsProvider CreateSettingsProvider() label = "Context Manager", guiHandler = (searchContext) => { +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT EditorGUILayout.LabelField("Global Settings", EditorStyles.boldLabel); using (new EditorGUILayout.HorizontalScope()) @@ -211,6 +201,9 @@ static SettingsProvider CreateSettingsProvider() } } } +#else + EditorGUILayout.HelpBox("EditorXR in Edit Mode requires legacy VR support, which was removed in Unity 2020.1. To use EditorXR in Edit Mode, you must use Unity 2019. To use EditorXR in Play Mode, add an EditingContextManager to your scene and install an XR Plugin.", MessageType.Warning); +#endif var contextTypes = CollectionPool, Type>.GetCollection(); typeof(IEditingContext).GetImplementationsOfInterface(contextTypes); @@ -233,6 +226,28 @@ static SettingsProvider CreateSettingsProvider() return provider; } +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT + [MenuItem("Window/EditorXR %e", false)] + internal static void ShowEditorXR() + { + if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying) + return; + + // Using a utility window improves performance by saving from the overhead of DockArea.OnGUI() + EditorWindow.GetWindow(true, "EditorXR", true); + } + + [MenuItem("Window/EditorXR %e", true)] + static bool ShouldShowEditorXR() + { + if (EditorApplication.isPlayingOrWillChangePlaymode || Application.isPlaying) + return false; + +#pragma warning disable 618 + return PlayerSettings.GetVirtualRealitySupported(BuildTargetGroup.Standalone); +#pragma warning restore 618 + } + static void OnAutoOpenStateChanged() { if (EditorApplication.isPlayingOrWillChangePlaymode) @@ -310,9 +325,7 @@ static void ReopenOnExitPlaymode() EditorApplication.delayCall += ShowEditorXR; } } -#endif -#if UNITY_EDITOR static void OnPlayModeStateChanged(PlayModeStateChange stateChange) { if (stateChange == PlayModeStateChange.ExitingEditMode) @@ -323,6 +336,7 @@ static void OnPlayModeStateChanged(PlayModeStateChange stateChange) view.Close(); } } +#endif #endif void OnEnable() @@ -334,7 +348,7 @@ void OnEnable() SetEditingContextMethods.setEditingContext = SetEditingContext; SetEditingContextMethods.restorePreviousEditingContext = RestorePreviousContext; -#if UNITY_EDITOR +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT if (runInEditMode) { // Force the window to repaint every tick, since we need live updating @@ -359,7 +373,7 @@ void OnDisable() { OnVRViewDisabled(); } -#if UNITY_EDITOR +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT else { EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; @@ -412,7 +426,7 @@ void Awake() if (s_AvailableContexts.Count == 0) throw new Exception("You can't start EditorXR without at least one context. Try re-importing the package or use version control to restore the default context asset"); -#if UNITY_EDITOR +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT if (s_AvailableContexts.Count > 1) VRView.afterOnGUI += OnVRViewGUI; #endif diff --git a/Runtime/Scripts/Core/EditorXR.cs b/Runtime/Scripts/Core/EditorXR.cs index 0941e6971..3458beb48 100644 --- a/Runtime/Scripts/Core/EditorXR.cs +++ b/Runtime/Scripts/Core/EditorXR.cs @@ -92,7 +92,7 @@ static void HandleInitialization() { s_IsInitialized = true; -#if UNITY_EDITOR +#if UNITY_EDITOR && !UNITY_2020_1_OR_NEWER #pragma warning disable 618 if (!PlayerSettings.GetVirtualRealitySupported(BuildTargetGroup.Standalone)) Debug.Log("EditorXR requires VR support. Please check Virtual Reality Supported in Edit->Project Settings->Player->XR Settings"); diff --git a/Runtime/Scripts/Core/VRView.cs b/Runtime/Scripts/Core/VRView.cs index b20fbd7aa..774a595fe 100644 --- a/Runtime/Scripts/Core/VRView.cs +++ b/Runtime/Scripts/Core/VRView.cs @@ -462,10 +462,12 @@ void DoDrawCamera(Rect rect) if (Event.current.type == EventType.Repaint) { +#pragma warning disable 618 if (XRDevice.isPresent) UnityEditor.Handles.DrawCamera(rect, m_Camera, m_RenderMode); else m_Camera.Render(); +#pragma warning restore 618 GUI.matrix = Matrix4x4.identity; // Need to push GUI matrix back to GPU after camera rendering RenderTexture.active = null; // Clean up after DrawCamera diff --git a/Tests/Editor/EditorXRTestInitializer.cs b/Tests/Editor/EditorXRTestInitializer.cs index f89ec0f6d..4b83af1a8 100644 --- a/Tests/Editor/EditorXRTestInitializer.cs +++ b/Tests/Editor/EditorXRTestInitializer.cs @@ -1,3 +1,8 @@ +// Edit mode support requires legacy VR, which was removed in 2020.1 +#if UNITY_EDITOR && !UNITY_2020_1_OR_NEWER +#define UNITY_EDITORXR_EDIT_MODE_SUPPORT +#endif + using NUnit.Framework; using Unity.EditorXR.Core; using UnityEditor; @@ -16,7 +21,9 @@ public void SetupBeforeAllTests() projectSettingsBackup = EditingContextManager.LoadProjectSettings(); userSettingsBackup = EditingContextManager.LoadUserSettings(); +#if UNITY_EDITORXR_EDIT_MODE_SUPPORT EditingContextManager.ShowEditorXR(); +#endif } [OneTimeTearDown]