diff --git a/Scripts/CSGModel.cs b/Scripts/CSGModel.cs index 20ee6d7d..51203e25 100644 --- a/Scripts/CSGModel.cs +++ b/Scripts/CSGModel.cs @@ -1330,6 +1330,13 @@ 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() { if (editMode && !anyCSGModelsInEditMode) @@ -1342,10 +1349,15 @@ 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 SceneView.onSceneGUIDelegate += OnSceneGUI; +#endif SceneView.RepaintAll(); } @@ -1429,7 +1441,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 +1454,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 +2066,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 +2142,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(); } 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 cfd92bcd..0b10e23f 100644 --- a/Scripts/UI/CSGGrid.cs +++ b/Scripts/UI/CSGGrid.cs @@ -16,15 +16,18 @@ 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 - SceneView.onSceneGUIDelegate += OnSceneGUI; - } + // resubscribe to the scene GUI updates. +#if UNITY_2019_1_OR_NEWER + SceneView.duringSceneGui -= OnSceneGUI; + SceneView.duringSceneGui += OnSceneGUI; +#else + SceneView.onSceneGUIDelegate -= OnSceneGUI; + 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 +42,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;