public void OnPreprocessBuild(BuildTarget target, string path) #endif { foreach (var inspector in InspectorManager.Instance().ActiveInstances) { var window = inspector.InspectorDrawer as PowerInspectorWindow; if (window != null) { window.editors.OnBeforeAssemblyReload(); } } }
public static bool WindowIsOpen() { #if UNITY_EDITOR if (!InspectorManager.InstanceExists()) { return(false); } var inspectors = InspectorManager.Instance().ActiveInstances; for (int n = inspectors.Count - 1; n >= 0; n--) { if (inspectors[n] is PowerInspector && IsPowerInspectorWindow(inspectors[n].InspectorDrawer)) { return(true); } } #endif return(false); }
private static void Setup() { // This helps fix issue where OdinEditor has not yet been injected into Unity's internal systems before building custom editor types for inspected components. if (!ApplicationUtility.IsReady()) { EditorApplication.delayCall += Setup; return; } // Wait until Inspector contents have been rebuilt using deserialized cached drawers // until moving on to fully rebuilding drawers from scratch. // This is because the process of building all the drawers can take a couple of seconds, // and we don't want to keep the user waiting for this duration. if (isReady) { foreach (var inspector in InspectorManager.Instance().ActiveInstances) { if (!inspector.SetupDone) { #if DEV_MODE && DEBUG_SETUP UnityEngine.Debug.Log("DefaultDrawerProviders - waiting until inspector Setup Done..."); #endif EditorApplication.delayCall += Setup; return; } } #if DEV_MODE && DEBUG_SETUP UnityEngine.Debug.Log("Setup now done for all " + InspectorManager.Instance().ActiveInstances.Count + " inspectors"); #endif } isReady = false; // Make sure that Preferences have been fetched via AssetDatabase.LoadAssetAtPath before moving on to threaded code var preferences = InspectorUtility.Preferences; UnityEngine.Debug.Assert(preferences != null); ThreadPool.QueueUserWorkItem(SetupThreaded); }
private static void ShowInSplitView() { var selected = Selection.objects; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(selected.Length > 0); #endif var manager = InspectorUtility.ActiveManager; if (manager == null) { manager = InspectorManager.Instance(); if (!InspectorUtility.Preferences.SetupDone && Event.current == null) { DrawGUI.OnNextBeginOnGUI(ShowInSplitView, true); return; } } var inspector = manager.LastSelectedActiveOrDefaultInspector(selected[0].IsSceneObject() ? InspectorTargetingMode.Hierarchy : InspectorTargetingMode.Project, InspectorSplittability.IsSplittable); ISplittableInspectorDrawer splittableDrawer; if (inspector == null) { splittableDrawer = PowerInspectorWindow.CreateNew(selected, true, false); } else { splittableDrawer = (ISplittableInspectorDrawer)inspector.InspectorDrawer; splittableDrawer.ShowInSplitView(selected); #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(splittableDrawer != null); Debug.Assert(selected[0].IsSceneObject() ? splittableDrawer.InspectorTargetingMode != InspectorTargetingMode.Hierarchy : splittableDrawer.InspectorTargetingMode != InspectorTargetingMode.Project); #endif } }
public static PowerInspector GetExistingWindow() { #if UNITY_EDITOR if (InspectorManager.InstanceExists()) { var inspector = InspectorManager.Instance().LastSelectedActiveOrDefaultInspector(InspectorSplittability.IsSplittable) as PowerInspector; if (inspector != null) { return(inspector); } var inspectors = InspectorManager.Instance().ActiveInstances; for (int n = inspectors.Count - 1; n >= 0; n--) { inspector = inspectors[n] as PowerInspector; if (inspector != null) { return(inspector); } } } #endif return(null); }
private static void ViewObjectInPowerInspector(MenuCommand command, bool useSplitView) { var manager = InspectorUtility.ActiveManager; if (manager == null) { manager = InspectorManager.Instance(); } var target = command.context; var gameObject = target.GameObject(); if (gameObject != null) { var inspector = manager.LastSelectedActiveOrDefaultInspector(gameObject.scene.IsValid() ? InspectorTargetingMode.Hierarchy : InspectorTargetingMode.Project); if (inspector == null) { var window = PowerInspectorWindow.CreateNew(false); inspector = window.MainView; manager.ActiveInspector = inspector; } if (useSplitView) { var splittableDrawer = inspector.InspectorDrawer as ISplittableInspectorDrawer; if (splittableDrawer != null) { splittableDrawer.ShowInSplitView(ArrayPool <Object> .CreateWithContent(gameObject)); inspector.ScrollToShow(target); return; } } else { inspector = inspector.InspectorDrawer.MainView; } inspector.RebuildDrawers(ArrayPool <Object> .CreateWithContent(gameObject), true); inspector.ScrollToShow(target); } else { var inspector = manager.LastSelectedActiveOrDefaultInspector(target.IsSceneObject() ? InspectorTargetingMode.Hierarchy : InspectorTargetingMode.Project); if (inspector == null) { var window = PowerInspectorWindow.CreateNew(false); inspector = window.MainView; manager.ActiveInspector = inspector; } if (useSplitView) { var splittableDrawer = inspector.InspectorDrawer as ISplittableInspectorDrawer; if (splittableDrawer != null) { splittableDrawer.ShowInSplitView(ArrayPool <Object> .CreateWithContent(target)); inspector.ScrollToShow(target); return; } } inspector.RebuildDrawers(ArrayPool <Object> .CreateWithContent(target), true); inspector.ScrollToShow(target); } }
/// <returns> True if should stop receiving OnGUIEvents. </returns> private static bool OnGUIStatic() { if (preferences == null) { #if UNITY_EDITOR if (EditorApplication.isCompiling) { #if DEV_MODE Debug.Log("OnGUIEventHelper - waiting before fetching preferences asset because still compiling scripts..."); #endif return(false); } if (EditorApplication.isUpdating) { #if DEV_MODE Debug.Log("OnGUIEventHelper - waiting before fetching preferences asset because still updating asset database..."); #endif return(false); } #endif try { preferences = InspectorUtility.Preferences; } #if DEV_MODE catch (NullReferenceException e) { Debug.LogWarning("OnGUIEventHelper.OnGUI failed to fetch preferences asset. " + e); #else catch (NullReferenceException) { #endif return(false); } if (preferences == null) { #if DEV_MODE Debug.LogWarning("OnGUIEventHelper.OnGUI failed to find preferences asset."); #endif return(false); } } preferences.Setup(); #if DEV_MODE && DEBUG_IS_STILL_NEEDED Debug.Log(StringUtils.ToColorizedString("EnsureOnGUICallbacks calling BeginOnGUI with isStillNeeded: " + isStillNeeded.Count + ", Event: ", Event.current)); #endif DrawGUI.BeginOnGUI(preferences, true); if (Event.current.type == EventType.Layout) { InspectorManager.Instance().OnLayout(); for (int n = isStillNeeded.Count - 1; n >= 0; n--) { if (isStillNeeded[n]()) { return(false); } } #if DEV_MODE && DEBUG_ENABLED Debug.Log("EnsureOnGUICallbacks closing because all " + isStillNeeded.Count + " isStillNeeded returned false"); #endif return(true); } return(false); }
public UnityEditor.EditorWindow GetLastSelectedEditorWindow() { if (UnityEditor.EditorWindow.focusedWindow != null) { return(UnityEditor.EditorWindow.focusedWindow); } if (lastSelectedEditorWindow != null) { return(lastSelectedEditorWindow as UnityEditor.EditorWindow); } // Since last selection data is lost every time the assembly is reloaded as fallback just return some instance. var inspectorManager = InspectorUtility.ActiveManager != null ? InspectorUtility.ActiveManager : InspectorManager.Instance(); var inspectors = inspectorManager.ActiveInstances; for (int n = inspectors.Count - 1; n >= 0; n--) { var editorWindow = inspectors[n].InspectorDrawer as UnityEditor.EditorWindow; if (editorWindow != null) { return(editorWindow); } } return(null); }
public IInspectorDrawer GetLastSelectedInspectorDrawer([NotNull] Type inspectorDrawerType) { IInspectorDrawer result; if (lastSelectedInspectorDrawers.TryGetValue(inspectorDrawerType, out result)) { return(result); } // Since last selection data is lost every time the assembly is reloaded as fallback just return some instance. var inspectorManager = InspectorUtility.ActiveManager != null ? InspectorUtility.ActiveManager : InspectorManager.Instance(); var inspectors = inspectorManager.ActiveInstances; for (int n = inspectors.Count - 1; n >= 0; n--) { var inspectorDrawer = inspectors[n].InspectorDrawer; if (inspectorDrawer.GetType() == inspectorDrawerType) { return(inspectorDrawer); } } return(null); }