/// <inheritdoc/> public void Select(Object target) { if (Selected.Length != 1 || Selected[0] != target) { Selected = ArrayPool <Object> .CreateWithContent(target); HandleCallbacks(); } }
public void Select(Object target) { if (lastSelection.Length != 1 || lastSelection[0] != target) { lastSelection = ArrayPool <Object> .CreateWithContent(target); HandleCallbacks(); } }
public void Select(Object target) { if (lockedSelection.Length == 0) { lockedSelection = ArrayPool <Object> .CreateWithContent(target); HandleCallbacks(); } }
public static UndoableModification Create([NotNull] LinkedMemberInfo setMemberInfo, object setValueTo) { UndoableModification created; if (!pool.TryGet(out created)) { created = new UndoableModification(); } created.Setup(setMemberInfo, ArrayPool <object> .CreateWithContent(setValueTo)); return(created); }
/// <inheritdoc/> public override void Select(Object target) { #if DEV_MODE && DEBUG_SELECT Debug.Log(ToString() + ".Select(" + StringUtils.ToString(target) + ")"); #endif #if UNITY_EDITOR Selection.activeObject = target; #else State.inspected = ArrayPool <Object> .CreateWithContent(target); #endif }
/// <inheritdoc /> public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly) { var type = DrawerUtility.GetType(setMemberInfo, setValue); if (type.IsArray) { Setup(setValue as ParameterInfo[], setMemberInfo, setParent, setLabel, setReadOnly); } else { Setup(ArrayPool <ParameterInfo> .CreateWithContent(setValue as ParameterInfo), setMemberInfo, setParent, setLabel, setReadOnly); } }
public static void ShowInSplitView(this ISplittableInspectorDrawer inspectorDrawer, Object target, bool throwExitGUIException) { #if DEV_MODE Debug.Log("ShowInSplitView(" + StringUtils.ToString(target) + ")"); #endif if (target != null) { var component = target as Component; if (component != null) { #if DEV_MODE Debug.Log("ShowInSplitView(" + StringUtils.TypeToString(target) + ") - was a Component"); #endif var gameObject = component.gameObject; inspectorDrawer.ShowInSplitView(ArrayPool <Object> .CreateWithContent(gameObject)); var splitBottom = inspectorDrawer.SplitView; // Wait one frame so that there's been time to cache all layout data during the next OnGUI call, // so that ScrollToShow can scroll to the correct position splitBottom.OnNextLayout(() => { var show = splitBottom.State.drawers.FindDrawer(component); if (show != null) { splitBottom.Manager.Select(splitBottom, InspectorPart.Viewport, show, ReasonSelectionChanged.Peek); splitBottom.ScrollToShow(show); show.SetUnfolded(true, false, false); ExitGUIUtility.ExitGUI(); } }); } else //GameObjects and Assets are okay to be shown as standalone { #if DEV_MODE Debug.Log("ShowInSplitView(" + StringUtils.TypeToString(target) + ") was not a Component"); #endif inspectorDrawer.ShowInSplitView(ArrayPool <Object> .CreateWithContent(target)); } if (throwExitGUIException) { ExitGUIUtility.ExitGUI(); } } }
public static PreferencesDrawer GetExistingOrCreateNewWindow() { var inspectorManager = InspectorUtility.ActiveManager; if (inspectorManager != null) { var preferencesInstance = (PowerInspectorPreferencesWindow)inspectorManager.GetLastSelectedInspectorDrawer(typeof(PowerInspectorPreferencesWindow)); if (preferencesInstance != null) { #if DEV_MODE && PI_ASSERTATIONS Debug.Assert((object)preferencesInstance != null); #endif #if DEV_MODE Debug.Log("Using existing preferences window: " + preferencesInstance); #endif preferencesInstance.FocusWindow(); return(GetPrefencesDrawer(preferencesInstance)); } } if (Event.current == null) { #if DEV_MODE Debug.LogWarning("Opening preferences window on next OnGUI. Returning null"); #endif DrawGUI.OnNextBeginOnGUI(Open, true); return(null); } #if DEV_MODE Debug.Log("Opening preferences window now!"); #endif var minSize = PreferencesDrawer.GetExpectedMinSize(); var created = CreateNew <PowerInspectorPreferencesWindow>("Preferences", ArrayPool <Object> .CreateWithContent(PowerInspector.GetPreferences()), true, false, minSize, minSize); return(GetPrefencesDrawer(created)); }
/// <inheritdoc/> protected override void BuildContextMenu(ref Menu menu, bool extendedMenu) { menu.Add("Debug Mode+/Off", "Disable Debug Mode For All Inspected Targets", inspector.DisableDebugMode, !inspector.State.DebugMode); menu.Add("Debug Mode+/On", "Enable Debug Mode For All Inspected Targets", inspector.EnableDebugMode, inspector.State.DebugMode); menu.AddSeparatorIfNotRedundant(); menu.Add("Multi-Editing/Merged", EnableMergedMultiEditMode, UserSettings.MergedMultiEditMode); menu.Add("Multi-Editing/Stacked", DisableMergedMultiEditMode, !UserSettings.MergedMultiEditMode); menu.Add("Help/Documentation", PowerInspectorDocumentation.Show); menu.Add("Help/Forum", OpenUrlFromContextMenu, "https://forum.unity.com/threads/released-power-inspector-full-inspector-overhaul.736022/"); menu.AddSeparator("Help/"); menu.Add("Help/Toolbar/Toolbar", PowerInspectorDocumentation.ShowFeature, "toolbar"); menu.Add("Help/Toolbar/Back And Forward Buttons", PowerInspectorDocumentation.ShowFeature, "back-and-forward-buttons"); menu.Add("Help/Toolbar/View Menu", PowerInspectorDocumentation.ShowFeature, "view-menu"); menu.Add("Help/Toolbar/Search Box", PowerInspectorDocumentation.ShowFeature, "search-box"); menu.Add("Help/Toolbar/Split View", PowerInspectorDocumentation.ShowFeature, "split-view"); menu.Add("Help/Features/Copy-Paste", PowerInspectorDocumentation.ShowFeature, "copy-paste"); menu.Add("Help/Features/Reset", PowerInspectorDocumentation.ShowFeature, "reset"); menu.Add("Help/Features/Context Menu", PowerInspectorDocumentation.ShowFeature, "context-menu-items"); menu.Add("Help/Features/Debug Mode+", PowerInspectorDocumentation.ShowFeature, "debug-mode"); menu.Add("Help/Features/Display Anything", PowerInspectorDocumentation.ShowFeature, "display-anything"); menu.Add("Help/Features/Hierarchy Folders", PowerInspectorDocumentation.ShowFeature, "hierarchy-folders"); menu.Add("Help/View Modes/Target Window", PowerInspectorDocumentation.ShowFeature, "target-window"); menu.Add("Help/View Modes/Multi-Editing Modes", PowerInspectorDocumentation.ShowFeature, "multi-editing-modes"); var rootDrawer = inspector.State.drawers.Members; for (int n = 0, count = rootDrawer.Length; n < count; n++) { var root = rootDrawer[n] as IRootDrawer; if (root != null) { root.AddItemsToOpeningViewMenu(ref menu); //break; //UPDATE: multiple drawers adding items to the menu should now be supported } } menu.AddSeparator(); menu.Add("Preferences", PowerInspectorPreferences.OpenIfNotOpenAndFocus); menu.AddSeparator(); menu.MoveCategoryToBottom("Help/"); menu.AddSeparator("Help/"); menu.Add("Help/Troubleshooting/Troubleshooting Documentation", PowerInspectorDocumentation.Show, "category/troubleshooting/"); menu.Add("Help/Troubleshooting/Issue Tracker", OpenUrlFromContextMenu, "https://github.com/SisusCo/Power-Inspector/issues"); #if UNITY_EDITOR if (extendedMenu) { menu.AddSeparator(); var windows = Resources.FindObjectsOfTypeAll <UnityEditor.EditorWindow>(); var self = inspector.InspectorDrawer as UnityEditor.EditorWindow; menu.Add("EditorWindow Debugger/this (" + self.GetType().Name + ")", () => PowerInspectorWindowUtility.OpenNewWindow(self, true, false)); for (int n = windows.Length - 1; n >= 0; n--) { var window = windows[n]; if (window == self) { continue; } menu.AddEvenIfDuplicate("EditorWindow Debugger/" + window.GetType().Name, () => { inspector.State.ViewIsLocked = true; inspector.RebuildDrawers(ArrayPool <UnityEngine.Object> .CreateWithContent(window), true); }); } } #endif }
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); } }
/// <inheritdoc/> public override void Select(Object target) { RebuildDrawers(ArrayPool <Object> .CreateWithContent(target), false); }
public static IInspectorDrawer OpenNewWindow(Object inspect, bool lockView = false, bool addAsTab = true, Vector2 minSize = default(Vector2)) { return(createNewWindow(ArrayPool <Object> .CreateWithContent(inspect), lockView, addAsTab, minSize)); }
public IDrawer GetForAsset([NotNull] IInspector inspector, [NotNull] Object target, [CanBeNull] IParentDrawer parent) { return(GetForAssets(inspector, ArrayPool <Object> .CreateWithContent(target), parent)); }
public IComponentDrawer GetForComponent(IInspector inspector, Component target, IParentDrawer parent) { return(GetForComponents(inspector, ArrayPool <Component> .CreateWithContent(target), parent)); }
/// <inheritdoc cref="GetEditor(ref Editor, Object, Type, Object, bool)"/> public void GetEditorInternal(ref Editor editor, [NotNull] Object target, Type editorType = null, Object context = null, bool cache = true) { if (editor != null) { #if !NET_STANDARD_2_0 var editorTargets = getTargets(editor); if (editorTargets.Length == 1 && editorTargets[0] == target && context == getContext(editor)) #else var editorTargets = getTargets.GetValue(editor) as Object[]; if (editorTargets.Length == 1 && editorTargets[0] == target && context == getContext.GetValue(editor) as Object) #endif { return; } DisposeInternal(ref editor); } #if UNITY_2017_2_OR_NEWER bool isAssetImporterEditor = editorType != null && Types.AssetImporterEditor.IsAssignableFrom(editorType); var editorKey = new EditorKey(target, isAssetImporterEditor); #else var editorKey = new EditorKey(target, false); #endif if (cachedEditors.TryGetValue(editorKey, out editor)) { if (editor != null) { if (!DisposeIfInvalid(ref editor)) { OnBecameActive(editor); #if DEV_MODE && DEBUG_GET_EDITOR Debug.Log("Editors.GetEditor: returning cached: " + editor.GetType().Name + " for " + StringUtils.ToString(target) + " with key=" + editorKey.GetHashCode()); #endif return; } #if DEV_MODE && DEBUG_DESTROYED_CACHED_EDITORS Debug.LogWarning("cachedEditors for target " + StringUtils.TypeToString(target) + " and editorType " + StringUtils.ToString(editorType) + " with EditorKey hashCode " + editorKey.GetHashCode() + " contained editor with null targets!\nCachedEditors:\n" + StringUtils.ToString(cachedEditors, "\n")); #endif } #if DEV_MODE && DEBUG_DESTROYED_CACHED_EDITORS else { Debug.LogWarning("cachedEditors for target " + StringUtils.TypeToString(target) + " and editorType " + StringUtils.ToString(editorType) + " with EditorKey hashCode " + editorKey.GetHashCode() + " contained a null value!\nCachedEditors:\n" + StringUtils.ToString(cachedEditors, "\n")); } #endif } #if DEV_MODE || IGNORE_GAMEOBJECT_EDITOR_OVERRIDES if (editorType == null) { if (target is GameObject) { editorType = GameObjectInspectorType; } } #endif editor = Editor.CreateEditorWithContext(ArrayPool <Object> .CreateWithContent(target), context, editorType); if (editor == null) { #if DEV_MODE Debug.LogWarning("Editor.CreateEditor for target " + StringUtils.TypeToString(target) + " and editorType " + StringUtils.ToString(editorType) + " returned null!"); #endif return; } #if DEV_MODE && DEBUG_GET_EDITOR Debug.Log("Editors.GetEditor: Created new: " + editor.GetType().Name + " for " + StringUtils.ToString(target) + " with key=" + editorKey.GetHashCode()); #endif if (cache) { cachedEditors[editorKey] = editor; } }
/// <summary> /// Use this for adding Undo support for changes that are not serialized by Unity when Unity can't handle undoing the action /// </summary> /// <param name="targets"> The UnityEngine.Object targets which contain the members which are being modified. </param> /// <param name="memberInfo"> The LinkedMemberInfo for the members which are being modified. This cannot be null. </param> /// <param name="valueTo"> The value to which the members will be set. </param> /// <param name="menuItemText"> Message describing the undo. </param> /// <param name="registerCompleteObjectUndo"> Set to true if full object hierarchy should be serialized for the Undo. This is needed for undoing changes to array size fields to function properly. </param> /// <returns> True if should call EditorUtility.SetDirty after value has changed. </returns> public static bool RegisterUndoableAction(Object[] targets, [NotNull] LinkedMemberInfo memberInfo, object valueTo, [NotNull] string menuItemText, bool registerCompleteObjectUndo) { return(RegisterUndoableAction(targets, memberInfo, ArrayPool <object> .CreateWithContent(valueTo), menuItemText, registerCompleteObjectUndo)); }