From fd0a014a796f2b84de78723a843b6e23acec6208 Mon Sep 17 00:00:00 2001 From: Henry de Jongh Date: Tue, 26 Nov 2019 17:48:40 +0100 Subject: [PATCH 1/4] Fixed Unity 2019 having no GUI. Fixes #234 and #233. --- Scripts/CSGModel.cs | 15 +++++++++- .../Compatibility/Editor/UnityEventDrawer.cs | 2 +- Scripts/Editor/Utilities/UtilityShortcuts.cs | 28 +++++++++++++------ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/Scripts/CSGModel.cs b/Scripts/CSGModel.cs index 20ee6d7d..6fee3703 100644 --- a/Scripts/CSGModel.cs +++ b/Scripts/CSGModel.cs @@ -1429,7 +1429,11 @@ private void OnDestroy() EditorApplication.update -= OnEditorUpdate; EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyItemGUI; EditorApplication.projectWindowItemOnGUI -= OnProjectItemGUI; +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui -= OnSceneGUI; +#else SceneView.onSceneGUIDelegate -= OnSceneGUI; +#endif Undo.undoRedoPerformed -= OnUndoRedoPerformed; GridManager.UpdateGrid(); @@ -1438,8 +1442,13 @@ private void OnDestroy() public void RebindToOnSceneGUI() { // Unbind the delegate, then rebind to ensure our method gets called last +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui -= OnSceneGUI; + SceneView.duringSceneGui += OnSceneGUI; +#else SceneView.onSceneGUIDelegate -= OnSceneGUI; SceneView.onSceneGUIDelegate += OnSceneGUI; +#endif } public void ExportOBJ(bool limitToSelection) @@ -2045,7 +2054,11 @@ private void ApplyModelAttributes(GameObject newGameObject, bool isVisual) if (buildSettings.GenerateLightmapUVs) { UnityEditor.StaticEditorFlags staticFlags = UnityEditor.GameObjectUtility.GetStaticEditorFlags(newGameObject); +#if UNITY_2019_1_OR_NEWER + staticFlags |= UnityEditor.StaticEditorFlags.ContributeGI; +#else staticFlags |= UnityEditor.StaticEditorFlags.LightmapStatic; +#endif UnityEditor.GameObjectUtility.SetStaticEditorFlags(newGameObject, staticFlags); } } @@ -2117,7 +2130,7 @@ void OnDrawGizmosSelected() } #endif #endif + } } -} #endif diff --git a/Scripts/Compatibility/Editor/UnityEventDrawer.cs b/Scripts/Compatibility/Editor/UnityEventDrawer.cs index 51b32687..3ee22419 100644 --- a/Scripts/Compatibility/Editor/UnityEventDrawer.cs +++ b/Scripts/Compatibility/Editor/UnityEventDrawer.cs @@ -1,4 +1,4 @@ -#if !UNITY_2018_OR_NEWER +#if !UNITY_2018_1_OR_NEWER using System; using System.Collections.Generic; using System.Linq; diff --git a/Scripts/Editor/Utilities/UtilityShortcuts.cs b/Scripts/Editor/Utilities/UtilityShortcuts.cs index 44c43af3..9c3f635a 100644 --- a/Scripts/Editor/Utilities/UtilityShortcuts.cs +++ b/Scripts/Editor/Utilities/UtilityShortcuts.cs @@ -98,16 +98,28 @@ static void CSG4Split() if(EditorHelper.GetSceneViewCamera(sceneView) == EditorHelper.SceneViewCamera.Other) { sceneView.orthographic = false; - sceneView.m_SceneLighting = true; - } - else +#if UNITY_2019_1_OR_NEWER + sceneView.sceneLighting = true; +#else + sceneView.m_SceneLighting = true; +#endif + } + else { sceneView.orthographic = true; - sceneView.m_SceneLighting = false; - SceneView.SceneViewState state = GetSceneViewState(sceneView); - state.Toggle(false); - } - } +#if UNITY_2019_1_OR_NEWER + sceneView.sceneLighting = false; +#else + sceneView.m_SceneLighting = false; +#endif + SceneView.SceneViewState state = GetSceneViewState(sceneView); +#if UNITY_2019_1_OR_NEWER + state.SetAllEnabled(false); +#else + state.Toggle(false); +#endif + } + } SceneView.RepaintAll(); } From 969b9942471ff2d34eb4dfb399c6d2ef99b97975 Mon Sep 17 00:00:00 2001 From: Henry de Jongh Date: Tue, 26 Nov 2019 18:04:24 +0100 Subject: [PATCH 2/4] Fixed additional cases where duringSceneGui has to be used. --- Scripts/CSGModel.cs | 4 ++++ Scripts/UI/CSGGrid.cs | 24 ++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Scripts/CSGModel.cs b/Scripts/CSGModel.cs index 6fee3703..52e72dcd 100644 --- a/Scripts/CSGModel.cs +++ b/Scripts/CSGModel.cs @@ -1345,7 +1345,11 @@ protected override void Update() if (!EditorHelper.SceneViewHasDelegate(OnSceneGUI)) { // Then resubscribe and repaint +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui += OnSceneGUI; +#else SceneView.onSceneGUIDelegate += OnSceneGUI; +#endif SceneView.RepaintAll(); } diff --git a/Scripts/UI/CSGGrid.cs b/Scripts/UI/CSGGrid.cs index cfd92bcd..a22662b2 100644 --- a/Scripts/UI/CSGGrid.cs +++ b/Scripts/UI/CSGGrid.cs @@ -20,11 +20,15 @@ public static void Activate() { if(!EditorHelper.SceneViewHasDelegate(OnSceneGUI)) { - // Then resubscribe and repaint - SceneView.onSceneGUIDelegate += OnSceneGUI; - } + // Then resubscribe and repaint +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui += OnSceneGUI; +#else + SceneView.onSceneGUIDelegate += OnSceneGUI; +#endif + } - CSGModel[] csgModels = Object.FindObjectsOfType(); + CSGModel[] csgModels = Object.FindObjectsOfType(); // Make sure the grid draws behind the CSG Model drawing. This requires us to ask the CSG Model to reregister for (int i = 0; i < csgModels.Length; i++) @@ -39,10 +43,14 @@ public static void Activate() public static void Deactivate() { - SceneView.onSceneGUIDelegate -= OnSceneGUI; - } - - static void OnSceneGUI(SceneView sceneView) +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui -= OnSceneGUI; +#else + SceneView.onSceneGUIDelegate -= OnSceneGUI; +#endif + } + + static void OnSceneGUI(SceneView sceneView) { Event e = Event.current; From 362b68be11639deeb51b8a8a16085b2c0645a315 Mon Sep 17 00:00:00 2001 From: Henry de Jongh Date: Tue, 26 Nov 2019 18:46:14 +0100 Subject: [PATCH 3/4] No longer using EditorHelper.SceneViewHasDelegate and instead relying on Unity resetting a private variable on recompilations. --- Scripts/CSGModel.cs | 9 ++++++++- Scripts/Extensions/EditorHelper.cs | 13 ++++++++----- Scripts/UI/CSGGrid.cs | 13 ++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Scripts/CSGModel.cs b/Scripts/CSGModel.cs index 52e72dcd..16c3f4c8 100644 --- a/Scripts/CSGModel.cs +++ b/Scripts/CSGModel.cs @@ -1330,6 +1330,12 @@ private void OnEditorUpdate() } } + /// + /// Used to determined whether we are subscribed to the "During scene GUI" event. + /// Recompilations will reset this variable to false and we can rebind. + /// + private bool isSubscribedToDuringSceneGui = false; + protected override void Update() { if (editMode && !anyCSGModelsInEditMode) @@ -1342,9 +1348,10 @@ protected override void Update() // Make sure the events we need to listen for are all bound (recompilation removes listeners, so it is // necessary to rebind dynamically) - if (!EditorHelper.SceneViewHasDelegate(OnSceneGUI)) + if (!isSubscribedToDuringSceneGui) { // Then resubscribe and repaint + isSubscribedToDuringSceneGui = true; #if UNITY_2019_1_OR_NEWER SceneView.duringSceneGui += OnSceneGUI; #else diff --git a/Scripts/Extensions/EditorHelper.cs b/Scripts/Extensions/EditorHelper.cs index ff81b459..1e17dd38 100644 --- a/Scripts/Extensions/EditorHelper.cs +++ b/Scripts/Extensions/EditorHelper.cs @@ -41,12 +41,15 @@ public static bool HasDelegate (System.Delegate mainDelegate, System.Delegate ta } } - public static bool SceneViewHasDelegate(SceneView.OnSceneFunc targetDelegate) - { - return HasDelegate(SceneView.onSceneGUIDelegate, targetDelegate); - } + /// + /// DO NOT USE - only here for compatibility with old third party plugins! + /// + public static bool SceneViewHasDelegate(SceneView.OnSceneFunc targetDelegate) + { + return HasDelegate(SceneView.onSceneGUIDelegate, targetDelegate); + } - public enum SceneViewCamera { Top, Bottom, Left, Right, Front, Back, Other }; + public enum SceneViewCamera { Top, Bottom, Left, Right, Front, Back, Other }; public static SceneViewCamera GetSceneViewCamera(SceneView sceneView) { diff --git a/Scripts/UI/CSGGrid.cs b/Scripts/UI/CSGGrid.cs index a22662b2..0b10e23f 100644 --- a/Scripts/UI/CSGGrid.cs +++ b/Scripts/UI/CSGGrid.cs @@ -16,17 +16,16 @@ public static class CSGGrid const float MAJOR_LINE_DISTANCE = 200; const float MINOR_LINE_DISTANCE = 50; - public static void Activate() + public static void Activate() { - if(!EditorHelper.SceneViewHasDelegate(OnSceneGUI)) - { - // Then resubscribe and repaint + // resubscribe to the scene GUI updates. #if UNITY_2019_1_OR_NEWER - SceneView.duringSceneGui += OnSceneGUI; + SceneView.duringSceneGui -= OnSceneGUI; + SceneView.duringSceneGui += OnSceneGUI; #else - SceneView.onSceneGUIDelegate += OnSceneGUI; + SceneView.onSceneGUIDelegate -= OnSceneGUI; + SceneView.onSceneGUIDelegate += OnSceneGUI; #endif - } CSGModel[] csgModels = Object.FindObjectsOfType(); From bc382d77fa8ff82ec3ce89d2a9ad59eb7d44ba3e Mon Sep 17 00:00:00 2001 From: Henry de Jongh Date: Tue, 26 Nov 2019 18:56:54 +0100 Subject: [PATCH 4/4] Ensure that the boolean is never serialized between script recompilations. --- Scripts/CSGModel.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Scripts/CSGModel.cs b/Scripts/CSGModel.cs index 16c3f4c8..51203e25 100644 --- a/Scripts/CSGModel.cs +++ b/Scripts/CSGModel.cs @@ -1334,6 +1334,7 @@ private void OnEditorUpdate() /// Used to determined whether we are subscribed to the "During scene GUI" event. /// Recompilations will reset this variable to false and we can rebind. /// + [NonSerialized] private bool isSubscribedToDuringSceneGui = false; protected override void Update()