From 955f73a259e194ca10c352282934777de5a98661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Castanheira?= Date: Fri, 26 Nov 2021 09:59:27 -0300 Subject: [PATCH 1/2] Fixes a reference error bug with play mode --- .../Scripts/View/GUI/EditModeGUI/EditModeToolWindow.Editor.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeToolWindow.Editor.cs b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeToolWindow.Editor.cs index 8cf2a37..8103908 100644 --- a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeToolWindow.Editor.cs +++ b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeToolWindow.Editor.cs @@ -10,7 +10,10 @@ public class EditModeToolWindowEditor : Editor public override void OnInspectorGUI() { if (EditorApplication.isPlayingOrWillChangePlaymode) + { + Selection.activeObject = null; return; + } RealtimeCSG.EditModeSelectionGUI.OnInspectorGUI(this, this.targets); } } \ No newline at end of file From e5beb7e0261997ae042f4be58428411dd49c5a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Castanheira?= Date: Wed, 1 Dec 2021 12:17:52 -0300 Subject: [PATCH 2/2] Adjust bottom bar position + Upgraded API --- .../InternalCSGModelManager.DefaultModel.cs | 6 + .../Scripts/Control/Managers/UpdateLoop.cs | 440 +++++++++--------- .../Editor/Scripts/Utility/PrefabUtility.cs | 178 +++---- .../SceneViewBottomBar.GUI.cs | 93 ++-- 4 files changed, 368 insertions(+), 349 deletions(-) diff --git a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.DefaultModel.cs b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.DefaultModel.cs index 8d94dd0..8624b28 100644 --- a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.DefaultModel.cs +++ b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.DefaultModel.cs @@ -88,7 +88,13 @@ static void InitializeDefaultCSGModel(Scene currentScene, CSGSceneState sceneSta bool inPrefabMode = false; Transform prefabRootTransform = null; #if UNITY_2018_3_OR_NEWER + +#if UNITY_2021_2_OR_NEWER + var currentPrefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#else var currentPrefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#endif + if (currentPrefabStage != null) { var prefabRoot = currentPrefabStage.prefabContentsRoot; diff --git a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/UpdateLoop.cs b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/UpdateLoop.cs index 3376404..5e053ee 100644 --- a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/UpdateLoop.cs +++ b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/UpdateLoop.cs @@ -11,52 +11,52 @@ namespace RealtimeCSG { - [InitializeOnLoad] - internal sealed class UpdateLoop - { - [MenuItem("Edit/Realtime-CSG/Turn Realtime-CSG on or off %F3", false, 30)] - static void ToggleRealtimeCSG() - { - RealtimeCSG.CSGSettings.SetRealtimeCSGEnabled(!RealtimeCSG.CSGSettings.EnableRealtimeCSG); - } - - public static bool IsActive() { return (editor != null && editor.initialized); } - - - static UpdateLoop editor = null; - static UpdateLoop() - { - if (editor != null) - { - editor.Shutdown(); - editor = null; - } - editor = new UpdateLoop(); - editor.Initialize(); - } + [InitializeOnLoad] + internal sealed class UpdateLoop + { + [MenuItem("Edit/Realtime-CSG/Turn Realtime-CSG on or off %F3", false, 30)] + static void ToggleRealtimeCSG() + { + RealtimeCSG.CSGSettings.SetRealtimeCSGEnabled(!RealtimeCSG.CSGSettings.EnableRealtimeCSG); + } - bool initialized = false; - bool had_first_update = false; + public static bool IsActive() { return (editor != null && editor.initialized); } - void Initialize() - { - if (initialized) - return; - CSGKeysPreferenceWindow.ReadKeys(); + static UpdateLoop editor = null; + static UpdateLoop() + { + if (editor != null) + { + editor.Shutdown(); + editor = null; + } + editor = new UpdateLoop(); + editor.Initialize(); + } + + bool initialized = false; + bool had_first_update = false; + + void Initialize() + { + if (initialized) + return; - initialized = true; - - CSGSceneManagerRedirector.Interface = new CSGSceneManagerInstance(); - - Selection.selectionChanged -= OnSelectionChanged; - Selection.selectionChanged += OnSelectionChanged; + CSGKeysPreferenceWindow.ReadKeys(); - EditorApplication.update -= OnFirstUpdate; - EditorApplication.update += OnFirstUpdate; + initialized = true; + + CSGSceneManagerRedirector.Interface = new CSGSceneManagerInstance(); + + Selection.selectionChanged -= OnSelectionChanged; + Selection.selectionChanged += OnSelectionChanged; + + EditorApplication.update -= OnFirstUpdate; + EditorApplication.update += OnFirstUpdate; #if UNITY_2018_1_OR_NEWER - EditorApplication.hierarchyChanged -= OnHierarchyWindowChanged; + EditorApplication.hierarchyChanged -= OnHierarchyWindowChanged; EditorApplication.hierarchyChanged += OnHierarchyWindowChanged; #else @@ -65,15 +65,19 @@ void Initialize() #endif #if UNITY_2018_3_OR_NEWER - UnityEditor.Experimental.SceneManagement.PrefabStage.prefabSaving += OnPrefabSaving; + #if UNITY_2021_2_OR_NEWER + UnityEditor.SceneManagement.PrefabStage.prefabSaving += OnPrefabSaving; + #else + UnityEditor.Experimental.SceneManagement.PrefabStage.prefabSaving += OnPrefabSaving; + #endif #endif - EditorApplication.hierarchyWindowItemOnGUI -= HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; - EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; - - UnityCompilerDefineManager.UpdateUnityDefines(); - } + EditorApplication.hierarchyWindowItemOnGUI -= HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; + EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; + + UnityCompilerDefineManager.UpdateUnityDefines(); + } #if UNITY_2018_3_OR_NEWER private void OnPrefabSaving(GameObject obj) @@ -84,142 +88,142 @@ private void OnPrefabSaving(GameObject obj) void Shutdown(bool finalizing = false) - { - if (editor != this) - return; + { + if (editor != this) + return; - editor = null; - CSGSceneManagerRedirector.Interface = null; - if (!initialized) - return; + editor = null; + CSGSceneManagerRedirector.Interface = null; + if (!initialized) + return; - EditorApplication.update -= OnFirstUpdate; + EditorApplication.update -= OnFirstUpdate; #if UNITY_2018_1_OR_NEWER - EditorApplication.hierarchyChanged -= OnHierarchyWindowChanged; + EditorApplication.hierarchyChanged -= OnHierarchyWindowChanged; #else EditorApplication.hierarchyWindowChanged -= OnHierarchyWindowChanged; #endif - EditorApplication.hierarchyWindowItemOnGUI -= HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; + EditorApplication.hierarchyWindowItemOnGUI -= HierarchyWindowItemGUI.OnHierarchyWindowItemOnGUI; #if UNITY_2019_1_OR_NEWER - SceneView.duringSceneGui -= SceneViewEventHandler.OnScene; + SceneView.duringSceneGui -= SceneViewEventHandler.OnScene; #else SceneView.onSceneGUIDelegate -= SceneViewEventHandler.OnScene; #endif - Undo.undoRedoPerformed -= UndoRedoPerformed; + Undo.undoRedoPerformed -= UndoRedoPerformed; - initialized = false; + initialized = false; - // make sure the C++ side of things knows to clear the method pointers - // so that we don't accidentally use them while closing unity - NativeMethodBindings.ClearUnityMethods(); - NativeMethodBindings.ClearExternalMethods(); + // make sure the C++ side of things knows to clear the method pointers + // so that we don't accidentally use them while closing unity + NativeMethodBindings.ClearUnityMethods(); + NativeMethodBindings.ClearExternalMethods(); - if (!finalizing) - SceneToolRenderer.Cleanup(); - } + if (!finalizing) + SceneToolRenderer.Cleanup(); + } - static Scene currentScene; - internal static void UpdateOnSceneChange() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) - return; + static Scene currentScene; + internal static void UpdateOnSceneChange() + { + if (EditorApplication.isPlayingOrWillChangePlaymode) + return; + + var activeScene = SceneManager.GetActiveScene(); + if (currentScene != activeScene) + { + if (editor == null) + ResetUpdateRoutine(); + + editor.OnSceneUnloaded(); + currentScene = activeScene; + InternalCSGModelManager.InitOnNewScene(); + } + } - var activeScene = SceneManager.GetActiveScene(); - if (currentScene != activeScene) - { - if (editor == null) - ResetUpdateRoutine(); + void OnSceneUnloaded() + { + if (EditorApplication.isPlayingOrWillChangePlaymode) + return; - editor.OnSceneUnloaded(); - currentScene = activeScene; - InternalCSGModelManager.InitOnNewScene(); - } - } - - void OnSceneUnloaded() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) - return; - - if (this.initialized) - this.Shutdown(); - - MeshInstanceManager.Shutdown(); - InternalCSGModelManager.Shutdown(); - - editor = new UpdateLoop(); - editor.Initialize(); - } - - public static void EnsureFirstUpdate() - { - if (editor == null) - return; - if (!editor.had_first_update) - editor.OnFirstUpdate(); - } - - void OnHierarchyWindowChanged() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) - return; - - SceneDragToolManager.UpdateDragAndDrop(); - InternalCSGModelManager.UpdateHierarchy(); - } - - void UndoRedoPerformed() - { - InternalCSGModelManager.UndoRedoPerformed(); - } - - // Delegate for generic updates - void OnFirstUpdate() - { - had_first_update = true; - EditorApplication.update -= OnFirstUpdate; - RealtimeCSG.CSGSettings.Reload(); - - // register unity methods in the c++ code so that some unity functions - // (such as debug.log) can be called from within the c++ code. - NativeMethodBindings.RegisterUnityMethods(); - - // register dll methods so we can use them - NativeMethodBindings.RegisterExternalMethods(); - - RunOnce(); - //CreateSceneChangeDetector(); - } - - void RunOnce() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) - { - // when you start playing the game in the editor, it'll call - // RunOnce before playing the game, but not after. - // so we need to wait until the game has stopped, after which we'll - // run first update again. - EditorApplication.update -= OnWaitUntillStoppedPlaying; - EditorApplication.update += OnWaitUntillStoppedPlaying; - return; - } + if (this.initialized) + this.Shutdown(); + + MeshInstanceManager.Shutdown(); + InternalCSGModelManager.Shutdown(); + + editor = new UpdateLoop(); + editor.Initialize(); + } + + public static void EnsureFirstUpdate() + { + if (editor == null) + return; + if (!editor.had_first_update) + editor.OnFirstUpdate(); + } + + void OnHierarchyWindowChanged() + { + if (EditorApplication.isPlayingOrWillChangePlaymode) + return; + + SceneDragToolManager.UpdateDragAndDrop(); + InternalCSGModelManager.UpdateHierarchy(); + } + + void UndoRedoPerformed() + { + InternalCSGModelManager.UndoRedoPerformed(); + } + + // Delegate for generic updates + void OnFirstUpdate() + { + had_first_update = true; + EditorApplication.update -= OnFirstUpdate; + RealtimeCSG.CSGSettings.Reload(); + + // register unity methods in the c++ code so that some unity functions + // (such as debug.log) can be called from within the c++ code. + NativeMethodBindings.RegisterUnityMethods(); + + // register dll methods so we can use them + NativeMethodBindings.RegisterExternalMethods(); + + RunOnce(); + //CreateSceneChangeDetector(); + } + + void RunOnce() + { + if (EditorApplication.isPlayingOrWillChangePlaymode) + { + // when you start playing the game in the editor, it'll call + // RunOnce before playing the game, but not after. + // so we need to wait until the game has stopped, after which we'll + // run first update again. + EditorApplication.update -= OnWaitUntillStoppedPlaying; + EditorApplication.update += OnWaitUntillStoppedPlaying; + return; + } #if UNITY_2019_1_OR_NEWER - SceneView.duringSceneGui -= SceneViewEventHandler.OnScene; - SceneView.duringSceneGui += SceneViewEventHandler.OnScene; + SceneView.duringSceneGui -= SceneViewEventHandler.OnScene; + SceneView.duringSceneGui += SceneViewEventHandler.OnScene; #else SceneView.onSceneGUIDelegate -= SceneViewEventHandler.OnScene; SceneView.onSceneGUIDelegate += SceneViewEventHandler.OnScene; #endif - Undo.undoRedoPerformed -= UndoRedoPerformed; - Undo.undoRedoPerformed += UndoRedoPerformed; - -// InternalCSGModelManager.UpdateHierarchy(); - - // but .. why? - /* + Undo.undoRedoPerformed -= UndoRedoPerformed; + Undo.undoRedoPerformed += UndoRedoPerformed; + + // InternalCSGModelManager.UpdateHierarchy(); + + // but .. why? + /* var scene = SceneManager.GetActiveScene(); var allGeneratedMeshes = SceneQueryUtility.GetAllComponentsInScene(scene); for (int i = 0; i < allGeneratedMeshes.Count; i++) @@ -229,71 +233,71 @@ void RunOnce() } */ - // we use a co-routine for updates because EditorApplication.update - // works at a ridiculous rate and the co-routine is only fired in the - // editor when something has happened. - ResetUpdateRoutine(); - } - - void OnWaitUntillStoppedPlaying() - { - if (!EditorApplication.isPlaying) - { - EditorApplication.update -= OnWaitUntillStoppedPlaying; + // we use a co-routine for updates because EditorApplication.update + // works at a ridiculous rate and the co-routine is only fired in the + // editor when something has happened. + ResetUpdateRoutine(); + } - EditorApplication.update -= OnFirstUpdate; - EditorApplication.update += OnFirstUpdate; - } - } - - static void RunEditorUpdate() - { - if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) - return; - - if (EditorApplication.isPlayingOrWillChangePlaymode) - return; - - UpdateLoop.UpdateOnSceneChange(); - - try - { - if (!ColorSettings.isInitialized) - ColorSettings.Update(); - InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: false); - TooltipUtility.CleanCache(); - } - catch (Exception ex) - { - Debug.LogException(ex); - } - } + void OnWaitUntillStoppedPlaying() + { + if (!EditorApplication.isPlaying) + { + EditorApplication.update -= OnWaitUntillStoppedPlaying; - public static void ResetUpdateRoutine() - { - if (EditorApplication.isPlayingOrWillChangePlaymode) - return; + EditorApplication.update -= OnFirstUpdate; + EditorApplication.update += OnFirstUpdate; + } + } - if (editor != null && - !editor.initialized) - { - editor = null; - } - if (editor == null) - { - editor = new UpdateLoop(); - editor.Initialize(); - } + static void RunEditorUpdate() + { + if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) + return; + + if (EditorApplication.isPlayingOrWillChangePlaymode) + return; + + UpdateLoop.UpdateOnSceneChange(); + + try + { + if (!ColorSettings.isInitialized) + ColorSettings.Update(); + InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: false); + TooltipUtility.CleanCache(); + } + catch (Exception ex) + { + Debug.LogException(ex); + } + } - EditorApplication.update -= RunEditorUpdate; - EditorApplication.update += RunEditorUpdate; - InternalCSGModelManager.skipCheckForChanges = false; - } + public static void ResetUpdateRoutine() + { + if (EditorApplication.isPlayingOrWillChangePlaymode) + return; + + if (editor != null && + !editor.initialized) + { + editor = null; + } + if (editor == null) + { + editor = new UpdateLoop(); + editor.Initialize(); + } + + EditorApplication.update -= RunEditorUpdate; + EditorApplication.update += RunEditorUpdate; + InternalCSGModelManager.skipCheckForChanges = false; + } - static void OnSelectionChanged() - { - EditModeManager.UpdateSelection(); - } - } + static void OnSelectionChanged() + { + EditModeManager.UpdateSelection(); + } + } } \ No newline at end of file diff --git a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Utility/PrefabUtility.cs b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Utility/PrefabUtility.cs index 05cd37b..a26264e 100644 --- a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Utility/PrefabUtility.cs +++ b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Utility/PrefabUtility.cs @@ -8,13 +8,13 @@ namespace RealtimeCSG { public sealed class CSGPrefabUtility { - public static UnityEngine.Object GetCorrespondingObjectFromSource(UnityEngine.Object source) - { - #if UNITY_2018_2_OR_NEWER - return PrefabUtility.GetCorrespondingObjectFromSource(source); - #else + public static UnityEngine.Object GetCorrespondingObjectFromSource(UnityEngine.Object source) + { +#if UNITY_2018_2_OR_NEWER + return PrefabUtility.GetCorrespondingObjectFromSource(source); +#else return PrefabUtility.GetPrefabParent(source); - #endif +#endif } public static bool IsPrefab(CSGModel model) @@ -31,18 +31,18 @@ public static bool IsPrefab(CSGModel model) public static bool AreInPrefabMode() { - #if UNITY_2018_3_OR_NEWER && UNITY_EDITOR +#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR var mainStage = StageUtility.GetMainStageHandle(); var currentStageHandle = StageUtility.GetCurrentStageHandle(); if (mainStage != currentStageHandle) return true; - #endif +#endif return false; } public static bool IsEditedInPrefabMode(CSGModel model) { - #if UNITY_2018_3_OR_NEWER && UNITY_EDITOR +#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR if (!model) return false; @@ -52,135 +52,139 @@ public static bool IsEditedInPrefabMode(CSGModel model) var currentStageHandle = StageUtility.GetCurrentStageHandle(); if (currentStageHandle.Contains(model.gameObject)) return true; - #endif +#endif return false; } public static CSGNode[] GetNodesInPrefabMode() { - #if UNITY_2018_3_OR_NEWER && UNITY_EDITOR +#if UNITY_2018_3_OR_NEWER && UNITY_EDITOR var mainStage = StageUtility.GetMainStageHandle(); var currentStageHandle = StageUtility.GetCurrentStageHandle(); if (mainStage != currentStageHandle) return currentStageHandle.FindComponentsOfType(); - #endif +#endif return null; } public static bool IsPrefabAssetOrInstance(GameObject gameObject) - { - #if UNITY_2018_3_OR_NEWER - var prefabAssetType = PrefabUtility.GetPrefabAssetType(gameObject); - var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(gameObject); - if (prefabAssetType == PrefabAssetType.NotAPrefab && - prefabInstanceType == PrefabInstanceStatus.NotAPrefab) - return false; - return true; - #else + { +#if UNITY_2018_3_OR_NEWER + var prefabAssetType = PrefabUtility.GetPrefabAssetType(gameObject); + var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(gameObject); + if (prefabAssetType == PrefabAssetType.NotAPrefab && + prefabInstanceType == PrefabInstanceStatus.NotAPrefab) + return false; + return true; +#else var prefabType = PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabType.None) return false; return true; - #endif - } - - public static bool IsPrefabAsset(GameObject gameObject) - { - #if UNITY_2018_3_OR_NEWER - var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(gameObject); - if (prefabInstanceType != PrefabInstanceStatus.NotAPrefab) - return false; - - var prefabType = PrefabUtility.GetPrefabAssetType(gameObject); - return prefabType != PrefabAssetType.NotAPrefab && - prefabType != PrefabAssetType.Model; - #else +#endif + } + + public static bool IsPrefabAsset(GameObject gameObject) + { +#if UNITY_2018_3_OR_NEWER + var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(gameObject); + if (prefabInstanceType != PrefabInstanceStatus.NotAPrefab) + return false; + + var prefabType = PrefabUtility.GetPrefabAssetType(gameObject); + return prefabType != PrefabAssetType.NotAPrefab && + prefabType != PrefabAssetType.Model; +#else var prefabType = PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabType.None) return false; return (prefabType == PrefabType.Prefab || prefabType == PrefabType.ModelPrefab); - #endif - } - - public static bool IsPrefabInstance(GameObject gameObject) - { - #if UNITY_2018_3_OR_NEWER +#endif + } + + public static bool IsPrefabInstance(GameObject gameObject) + { +#if UNITY_2018_3_OR_NEWER if (!PrefabUtility.IsPartOfAnyPrefab(gameObject)) return false; var prefabType = PrefabUtility.GetPrefabInstanceStatus(gameObject); - return prefabType != PrefabInstanceStatus.NotAPrefab; - #else + return prefabType != PrefabInstanceStatus.NotAPrefab; +#else var prefabType = PrefabUtility.GetPrefabType(gameObject); if (prefabType == PrefabType.None) return false; return (prefabType != PrefabType.Prefab && prefabType != PrefabType.ModelPrefab); - #endif - } +#endif + } public static GameObject GetPrefabAsset(GameObject gameObject) { - #if UNITY_2018_3_OR_NEWER +#if UNITY_2018_3_OR_NEWER if (AreInPrefabMode()) { +#if UNITY_2021_2_OR_NEWER + var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#else var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); +#endif if (prefabStage.IsPartOfPrefabContents(gameObject)) - #if UNITY_2020_1_OR_NEWER +#if UNITY_2020_1_OR_NEWER return (GameObject)AssetDatabase.LoadMainAssetAtPath(prefabStage.assetPath); - #else +#else return (GameObject)AssetDatabase.LoadMainAssetAtPath(prefabStage.prefabAssetPath); - #endif +#endif } - #endif +#endif if (!IsPrefabInstance(gameObject)) return null; - #if UNITY_2018_3_OR_NEWER +#if UNITY_2018_3_OR_NEWER return (GameObject)AssetDatabase.LoadMainAssetAtPath(PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(gameObject)); - #else +#else return (GameObject)PrefabUtility.GetPrefabParent(gameObject); - #endif +#endif } public static GameObject GetOutermostPrefabInstanceRoot(GameObject gameObject) - { - if (!IsPrefabInstance(gameObject)) - return null; - #if UNITY_2018_3_OR_NEWER - return PrefabUtility.GetOutermostPrefabInstanceRoot(gameObject); - #else + { + if (!IsPrefabInstance(gameObject)) + return null; +#if UNITY_2018_3_OR_NEWER + return PrefabUtility.GetOutermostPrefabInstanceRoot(gameObject); +#else return PrefabUtility.FindPrefabRoot(gameObject); - #endif - } - - public static GameObject Instantiate(GameObject originalGameObject, bool copy = false) - { - #if UNITY_2018_3_OR_NEWER - var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(originalGameObject); - if (prefabInstanceType != PrefabInstanceStatus.NotAPrefab && !copy) - { - var corrObj = GetCorrespondingObjectFromSource(originalGameObject); - var obj = PrefabUtility.InstantiatePrefab(corrObj); - var result = obj as GameObject; - return result; - } - - var prefabAssetType = PrefabUtility.GetPrefabAssetType(originalGameObject); - if (prefabAssetType != PrefabAssetType.NotAPrefab && !copy) - { - var obj = PrefabUtility.InstantiatePrefab(originalGameObject); - var result = obj as GameObject; - return result; - } - - var inst = UnityEngine.Object.Instantiate(originalGameObject); - return inst; - #else +#endif + } + + public static GameObject Instantiate(GameObject originalGameObject, bool copy = false) + { +#if UNITY_2018_3_OR_NEWER + var prefabInstanceType = PrefabUtility.GetPrefabInstanceStatus(originalGameObject); + if (prefabInstanceType != PrefabInstanceStatus.NotAPrefab && !copy) + { + var corrObj = GetCorrespondingObjectFromSource(originalGameObject); + var obj = PrefabUtility.InstantiatePrefab(corrObj); + var result = obj as GameObject; + return result; + } + + var prefabAssetType = PrefabUtility.GetPrefabAssetType(originalGameObject); + if (prefabAssetType != PrefabAssetType.NotAPrefab && !copy) + { + var obj = PrefabUtility.InstantiatePrefab(originalGameObject); + var result = obj as GameObject; + return result; + } + + var inst = UnityEngine.Object.Instantiate(originalGameObject); + return inst; +#else var prefabType = PrefabUtility.GetPrefabType(originalGameObject); if (prefabType == PrefabType.None || copy) return UnityEngine.Object.Instantiate(originalGameObject); @@ -192,8 +196,8 @@ public static GameObject Instantiate(GameObject originalGameObject, bool copy = else // PrefabInstance return PrefabUtility.InstantiatePrefab(GetCorrespondingObjectFromSource(originalGameObject)) as GameObject; - #endif - } +#endif + } internal static bool IsPartOfAsset(Mesh sharedMesh) { diff --git a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/SceneViewBottomBarGUI/SceneViewBottomBar.GUI.cs b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/SceneViewBottomBarGUI/SceneViewBottomBar.GUI.cs index 6abfd9e..dd5550f 100644 --- a/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/SceneViewBottomBarGUI/SceneViewBottomBar.GUI.cs +++ b/RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/SceneViewBottomBarGUI/SceneViewBottomBar.GUI.cs @@ -24,8 +24,13 @@ public static void ShowGUI(SceneView sceneView, bool haveOffset = true) Rect bottomBarRect; if (haveOffset) { +#if UNITY_2021_2_OR_NEWER + bottomBarRect = new Rect(0, height - (CSG_GUIStyleUtility.BottomToolBarHeight + 27), + width, CSG_GUIStyleUtility.BottomToolBarHeight); +#else bottomBarRect = new Rect(0, height - (CSG_GUIStyleUtility.BottomToolBarHeight + 18), width, CSG_GUIStyleUtility.BottomToolBarHeight); +#endif } else bottomBarRect = new Rect(0, height - (CSG_GUIStyleUtility.BottomToolBarHeight + 1), width, CSG_GUIStyleUtility.BottomToolBarHeight); @@ -97,7 +102,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) currentRect.x = layoutX; layoutX += currentRect.width; - #region "Grid" button +#region "Grid" button if (showGrid) { showGrid = GUI.Toggle(currentRect, showGrid, skin.gridIconOn, EditorStyles.toolbarButton); @@ -107,7 +112,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } //(x:6.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(showGridTooltip, currentRect); - #endregion +#endregion if (viewWidth >= 800) layoutX += 6; //(x:33.00, y:0.00, width:6.00, height:6.00) @@ -117,7 +122,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) if (lockAxisX) GUI.backgroundColor = lockedBackgroundColor; - #region "X" lock button +#region "X" lock button currentRect.width = 17; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; @@ -132,9 +137,9 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) else TooltipUtility.SetToolTip(xTooltipOff, currentRect); GUI.backgroundColor = prevBackgroundColor; - #endregion +#endregion - #region "Y" lock button +#region "Y" lock button currentRect.x = layoutX; layoutX += currentRect.width; @@ -147,9 +152,9 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) else TooltipUtility.SetToolTip(yTooltipOff, currentRect); GUI.backgroundColor = prevBackgroundColor; - #endregion +#endregion - #region "Z" lock button +#region "Z" lock button currentRect.x = layoutX; layoutX += currentRect.width; @@ -162,14 +167,14 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) else TooltipUtility.SetToolTip(zTooltipOff, currentRect); GUI.backgroundColor = prevBackgroundColor; - #endregion +#endregion } modified = GUI.changed || modified; if (viewWidth >= 800) layoutX += 6; // (x:91.00, y:0.00, width:6.00, height:6.00) - #region "SnapMode" button +#region "SnapMode" button GUI.changed = false; { currentRect.width = 27; @@ -219,13 +224,13 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } } modified = GUI.changed || modified; - #endregion +#endregion if (viewWidth >= 460) { if (snapMode != SnapMode.None) { - #region "Position" label +#region "Position" label if (viewWidth >= 500) { if (viewWidth >= 865) @@ -256,11 +261,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) TooltipUtility.SetToolTip(positionTooltip, currentRect); } } - #endregion +#endregion layoutX += 2; - #region "Position" field +#region "Position" field if (uniformGrid || viewWidth < 515) { EditorGUI.showMixedValue = !(moveSnapVector.x == moveSnapVector.y && moveSnapVector.x == moveSnapVector.z); @@ -316,11 +321,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } modified = GUI.changed || modified; } - #endregion +#endregion layoutX++; - #region "Position" Unit +#region "Position" Unit DistanceUnit nextUnit = Units.CycleToNextUnit(distanceUnit); GUIContent unitText = Units.GetUnitGUIContent(distanceUnit); @@ -336,11 +341,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) distanceUnit = nextUnit; modified = true; } - #endregion +#endregion layoutX += 2; - #region "Position" +/- +#region "Position" +/- if (viewWidth >= 700) { currentRect.width = 19; @@ -365,11 +370,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) //(x:429.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(positionMinnusTooltip, currentRect); } - #endregion +#endregion layoutX += 2; - #region "Angle" label +#region "Angle" label if (viewWidth >= 750) { if (viewWidth >= 865) @@ -397,11 +402,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } TooltipUtility.SetToolTip(angleTooltip, currentRect); } - #endregion +#endregion layoutX += 2; - #region "Angle" field +#region "Angle" field GUI.changed = false; { currentRect.width = 70; @@ -417,11 +422,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) TooltipUtility.SetToolTip(angleTooltip, currentRect); } modified = GUI.changed || modified; - #endregion +#endregion layoutX++; - #region "Angle" Unit +#region "Angle" Unit if (viewWidth >= 370) { currentRect.width = 14; @@ -433,11 +438,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) GUI.Label(currentRect, angleUnitLabel, miniTextStyle); } - #endregion +#endregion layoutX += 2; - #region "Angle" +/- +#region "Angle" +/- if (viewWidth >= 700) { currentRect.width = 19; @@ -463,11 +468,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) //(x:592.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(angleMinnusTooltip, currentRect); } - #endregion +#endregion layoutX += 2; - #region "Scale" label +#region "Scale" label if (viewWidth >= 750) { if (viewWidth >= 865) @@ -495,11 +500,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } TooltipUtility.SetToolTip(scaleTooltip, currentRect); } - #endregion +#endregion layoutX += 2; - #region "Scale" field +#region "Scale" field GUI.changed = false; { currentRect.width = 70; @@ -515,11 +520,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) TooltipUtility.SetToolTip(scaleTooltip, currentRect); } modified = GUI.changed || modified; - #endregion +#endregion layoutX ++; - #region "Scale" Unit +#region "Scale" Unit if (viewWidth >= 370) { currentRect.width = 15; @@ -532,11 +537,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) GUI.Label(currentRect, scaleUnitLabel, miniTextStyle); //(x:722.00, y:2.00, width:15.00, height:16.00) } - #endregion +#endregion layoutX += 2; - #region "Scale" +/- +#region "Scale" +/- if (viewWidth >= 700) { currentRect.width = 19; @@ -562,7 +567,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) //(x:760.00, y:2.00, width:17.00, height:15.00) TooltipUtility.SetToolTip(scaleMinnusTooltip, currentRect); } - #endregion +#endregion } } @@ -572,7 +577,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) layoutX = viewWidth; - #region "Rebuild" +#region "Rebuild" currentRect.width = 27; currentRect.y = 0; currentRect.height = layoutHeight - currentRect.y; @@ -626,12 +631,12 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) } //(x:1442.00, y:0.00, width:27.00, height:18.00) TooltipUtility.SetToolTip(rebuildTooltip, currentRect); - #endregion +#endregion if (viewWidth >= 800) layoutX -= 6; //(x:1436.00, y:0.00, width:6.00, height:6.00) - #region "Helper Surface Flags" Mask +#region "Helper Surface Flags" Mask if (viewWidth >= 250) { GUI.changed = false; @@ -658,9 +663,9 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) modified = true; } } - #endregion +#endregion - #region "Show wireframe" button +#region "Show wireframe" button GUI.changed = false; currentRect.width = 26; currentRect.y = 0; @@ -684,13 +689,13 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) wireframeModified = true; modified = true; } - #endregion +#endregion - #region Capture mouse clicks in empty space +#region Capture mouse clicks in empty space var mousePoint = Event.current.mousePosition; int controlID = GUIUtility.GetControlID(BottomBarEditorOverlayHash, FocusType.Passive, barSize); switch (Event.current.GetTypeForControl(controlID)) @@ -701,11 +706,11 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) case EventType.MouseDrag: { if (GUIUtility.hotControl == controlID) { Event.current.Use(); } break; } case EventType.ScrollWheel: { if (barSize.Contains(mousePoint)) { Event.current.Use(); } break; } } - #endregion +#endregion - #region Store modified values +#region Store modified values rotationSnap = Mathf.Max(1.0f, Mathf.Abs((360 + (rotationSnap % 360))) % 360); moveSnapVector.x = Mathf.Max(1.0f / 1024.0f, moveSnapVector.x); moveSnapVector.y = Mathf.Max(1.0f / 1024.0f, moveSnapVector.y); @@ -743,7 +748,7 @@ static void OnBottomBarGUI(SceneView sceneView, Rect barSize) RealtimeCSG.CSGSettings.Save(); CSG_EditorGUIUtility.RepaintAll(); } - #endregion +#endregion } }