Skip to content

Commit

Permalink
Suppress warnings in 2020.1;
Browse files Browse the repository at this point in the history
Add UNITY_EDITORXR_EDIT_MODE_SUPPORT define to disable menu item and edit-mode settings in 2020.1 and above;
Add warning HelpBox to settings menu about edit mode support
  • Loading branch information
mtschoen-unity committed Aug 20, 2020
1 parent a30c27d commit 8508727
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 36 deletions.
84 changes: 49 additions & 35 deletions Runtime/Scripts/Core/Contexts/EditingContextManager.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -74,11 +84,6 @@ internal static IEditingContext defaultContext
set { settings.defaultContextName = value.name; }
}

internal IEditingContext currentContext
{
get { return m_CurrentContext; }
}

static EditingContextManagerSettings settings
{
get
Expand All @@ -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;
Expand All @@ -119,7 +129,7 @@ static void OnVRViewEnabled()

static void OnVRViewDisabled()
{
#if UNITY_EDITOR
#if UNITY_EDITORXR_EDIT_MODE_SUPPORT
s_AutoOpened = false;
#endif

Expand All @@ -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<VRView>(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()
{
Expand All @@ -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())
Expand Down Expand Up @@ -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<List<Type>, Type>.GetCollection();
typeof(IEditingContext).GetImplementationsOfInterface(contextTypes);
Expand All @@ -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<VRView>(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)
Expand Down Expand Up @@ -310,9 +325,7 @@ static void ReopenOnExitPlaymode()
EditorApplication.delayCall += ShowEditorXR;
}
}
#endif

#if UNITY_EDITOR
static void OnPlayModeStateChanged(PlayModeStateChange stateChange)
{
if (stateChange == PlayModeStateChange.ExitingEditMode)
Expand All @@ -323,6 +336,7 @@ static void OnPlayModeStateChanged(PlayModeStateChange stateChange)
view.Close();
}
}
#endif
#endif

void OnEnable()
Expand All @@ -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
Expand All @@ -359,7 +373,7 @@ void OnDisable()
{
OnVRViewDisabled();
}
#if UNITY_EDITOR
#if UNITY_EDITORXR_EDIT_MODE_SUPPORT
else
{
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Scripts/Core/EditorXR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<color=orange>EditorXR requires VR support. Please check Virtual Reality Supported in Edit->Project Settings->Player->XR Settings</color>");
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Scripts/Core/VRView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions Tests/Editor/EditorXRTestInitializer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,7 +21,9 @@ public void SetupBeforeAllTests()
projectSettingsBackup = EditingContextManager.LoadProjectSettings();
userSettingsBackup = EditingContextManager.LoadUserSettings();

#if UNITY_EDITORXR_EDIT_MODE_SUPPORT
EditingContextManager.ShowEditorXR();
#endif
}

[OneTimeTearDown]
Expand Down

0 comments on commit 8508727

Please sign in to comment.