public static void OnExecuteCommand(this IInspectorDrawer inspectorDrawer, Event e)
        {
            if (DrawGUI.ExecutingCustomMenuCommand || !inspectorDrawer.HasFocus)
            {
                                #if DEV_MODE && DEBUG_IGNORED_COMMANDS
                Debug.LogWarning(StringUtils.ToColorizedString("Ignoring ExecuteCommand with name \"", e.commandName + "\"\nDrawer.HasFocus=", inspectorDrawer.HasFocus, ", ExecutingCustomMenuCommand=", DrawGUI.ExecutingCustomMenuCommand, ", FocusedDrawer=" + inspectorDrawer.Manager.FocusedControl));
                                #endif
                return;
            }

                        #if DEV_MODE && DEBUG_EXECUTE_COMMAND
            if (!string.Equals(e.commandName, "NewKeyboardFocus", System.StringComparison.Ordinal))
            {
                Debug.Log("Detected ExecuteCommand with name: " + e.commandName + "\nFocusedControl=" + StringUtils.ToString(inspectorDrawer.Manager.FocusedControl) + ", keyCode=" + e.keyCode);
            }
                        #endif

                        #if DEV_MODE && DEBUG_NEW_KEYBOARD_FOCUS
            if (string.Equals(e.commandName, "NewKeyboardFocus", System.StringComparison.Ordinal))
            {
                var m = inspectorDrawer.Manager;
                Debug.Log(StringUtils.ToColorizedString("NewKeyboardFocus part=", m.SelectedInspectorPart, ", control=", m.FocusedControl, ", KeyboardControl=", KeyboardControlUtility.KeyboardControl));
            }
                        #endif

            var selectedView = inspectorDrawer.SelectedOrDefaultView();
            if (selectedView != null && inspectorDrawer.HasFocus)
            {
                selectedView.OnExecuteCommand(e);
            }
        }
Example #2
0
        private void AfterUndoOrRedo()
        {
            var inspector = InspectorUtility.ActiveInspector;

            if (inspector != null)
            {
                // Disable the undo system temporarily so that new undo entries aren't generated as unintended side effects
                // when cached values in the inspector are updated (this should not happen, but making sure).
                Disable();
                onUpdateBroadcaster           = inspector.InspectorDrawer;
                onUpdateBroadcaster.OnUpdate += EnableDelayedAfterOnUpdate;

                // Stop editing text field when Undo is detected, so that if the value that was undone
                // is the field that is being edited, the changes will be seen immediately.
                if (DrawGUI.EditingTextField)
                {
                    var focusedDrawer = inspector.Manager.FocusedControl;
                    if (focusedDrawer != null)
                    {
                        DrawGUI.EditingTextField = false;
                    }
                }
            }

            if (OnOndoOrRedoPerformed != null)
            {
                OnOndoOrRedoPerformed();
            }
        }
Example #3
0
        public IInspector Create(Type inspectorType, IInspectorDrawer drawer, InspectorPreferences preferences, Object[] inspected, Vector2 scrollPos, bool viewIsLocked)
        {
            IInspector result;
            object     instanceFromPool;

            if (pool.TryGet(inspectorType, out instanceFromPool))
            {
                result = (IInspector)instanceFromPool;;
            }
            else
            {
                result = (IInspector)inspectorType.CreateInstance();
            }
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!activeInstances.Contains(result));
            Debug.Assert(!activeInstances.Contains(null));
                        #endif
            AddToActiveInstances(result);
            result.Setup(drawer, preferences, inspected, scrollPos, viewIsLocked);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(activeInstances.Contains(result), "Created inspector " + result + " not found in InspectorManager.activeInstances");
            Debug.Assert(!pool.Contains(result), "Created inspector " + result + " still found in InspectorManager.pool");
                        #endif

            return(result);
        }
Example #4
0
        private void StopTween()
        {
                        #if DEV_MODE && DEBUG_ENABLED
            UnityEngine.Debug.Log(StringUtils.ToColorizedString("TweenedBool.StopTween with tweenProgress=", tweenProgress, ", targetValue=", targetValue, ", NowTweening=", NowTweening));
                        #endif

            inspectorDrawer.OnUpdate -= Update;
            tweeningCount--;
            //DrawGUI.CancelOnEveryBeginOnGUI(inspectorDrawer.Repaint);

            inspectorDrawer = null;

            if (targetValue)
            {
                if (tweenProgress >= 1f)
                {
                    if (onTweenFinished != null)
                    {
                        var callback = onTweenFinished;
                        onTweenFinished = null;
                        callback(targetValue);
                    }
                }
            }
            else if (tweenProgress <= 0f)
            {
                if (onTweenFinished != null)
                {
                    var callback = onTweenFinished;
                    onTweenFinished = null;
                    callback(targetValue);
                }
            }
        }
Example #5
0
        /// <inheritdoc/>
        public override void Setup(IInspectorDrawer drawer, InspectorPreferences setPreferences, Object[] inspected, Vector2 scrollPos, bool viewIsLocked)
        {
                        #if DEV_MODE && DEBUG_SETUP_TIME
            var timer = new ExecutionTimeLogger();
            timer.Start(GetType().Name + ".Setup");
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setPreferences != null);
                        #endif

            previewDrawer = new PreviewDrawer(this);

            // Call base.Setup before calling Setup for the toolbar, so that the Preferences field gets assigned first
            base.Setup(drawer, setPreferences, inspected, scrollPos, viewIsLocked);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(Preferences != null);
            Debug.Assert(Preferences == setPreferences);
                        #endif

                        #if DEV_MODE && DEBUG_SETUP_TIME
            timer.FinishAndLogResults();
                        #endif
        }
        public static IInspector SelectedOrDefaultView(this IInspectorDrawer inspectorDrawer)
        {
            var mainView   = inspectorDrawer.MainView;
            var splittable = inspectorDrawer as ISplittableInspectorDrawer;

            if (splittable != null && splittable.ViewIsSplit)
            {
                var manager  = splittable.Manager;
                var selected = manager.SelectedInspector;
                if (mainView == selected)
                {
                    return(mainView);
                }

                var splitView = splittable.SplitView;
                if (splitView == selected)
                {
                    return(splitView);
                }

                if (splitView == manager.ActiveInspector)
                {
                    return(splitView);
                }
            }
            return(mainView);
        }
Example #7
0
 public void Dispose()
 {
     if (inspectorDrawer != null)
     {
         inspectorDrawer.OnUpdate -= Update;
         inspectorDrawer           = null;
     }
 }
Example #8
0
        /// <inheritdoc/>
        public void OnNextLayout(IDrawerDelayableAction action, IInspectorDrawer changingInspectorDrawer = null)
        {
            onNextLayoutDelayed.Enqueue(action);

            if (changingInspectorDrawer != null)
            {
                changingInspectorDrawer.RefreshView();
            }
            else
            {
                EnsureOnGUICallbacks(true);
            }
        }
        /// <inheritdoc/>
        public override void Setup(IInspectorDrawer drawer, InspectorPreferences setPreferences, Object[] inspected, Vector2 scrollPos, bool viewIsLocked)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(setPreferences != null);
                        #endif

            // Call base.Setup before calling Setup for the toolbar, so that the Preferences field gets assigned first
            base.Setup(drawer, setPreferences, inspected, scrollPos, viewIsLocked);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(Preferences != null);
            Debug.Assert(Preferences == setPreferences);
                        #endif
        }
Example #10
0
        public void SetTarget([NotNull] IInspectorDrawer inspectorDrawer, bool setTarget, Action <bool> onFinished = null)
        {
                        #if DEV_MODE && DEBUG_ENABLED
            UnityEngine.Debug.Log(StringUtils.ToColorizedString("TweenedBool.SetTarget(", setTarget, ") with tweenProgress=", tweenProgress, ", targetValue=", targetValue, ", NowTweening=", NowTweening, ", onFinished=", onFinished));
                        #endif

                        #if SAFE_MODE || DEV_MODE
            if (inspectorDrawer == null)
            {
                UnityEngine.Debug.LogError("TweenedBool.SetTarget called with null inspectorDrawer. Use SetValueInstant instead!");

                targetValue   = setTarget;
                tweenProgress = setTarget ? 1f : 0f;
                return;
            }
                        #endif

            targetValue = setTarget;

            // stop any tweens in progress
            if (NowTweening)
            {
                StopTween();
            }

            // if already at target value, we don't need to do any tweening
            // and should call onFinished immediately
            if (setTarget ? tweenProgress >= 1f : tweenProgress <= 0f)
            {
                if (onFinished != null)
                {
                    onFinished(targetValue);
                }
                return;
            }

            onTweenFinished     += onFinished;
            this.inspectorDrawer = inspectorDrawer;

            StartTween();

            // if tween speed is invalid value or extremely high value
            // then skip the animation completely
            if (tweenSpeed <= 0f || tweenSpeed >= 144f)
            {
                SetValueInstant(targetValue);
            }
        }
Example #11
0
 private void Awake()
 {
     if (inspectorDrawer == null)
     {
         var componentTypes = TypeExtensions.GetImplementingComponentTypes(typeof(IInspectorDrawer), false);
         for (int n = componentTypes.Length - 1; n >= 0; n--)
         {
             inspectorDrawer = GetComponent(componentTypes[n]) as IInspectorDrawer;
             if (inspectorDrawer != null)
             {
                 break;
             }
         }
         Debug.Assert(inspectorDrawer != null, "InspectorClickSelector could not find any Component implementing ISelectionManager in scene!");
     }
 }
Example #12
0
        /// <summary>
        /// Method used for creating new Inspector instances. All instances should be
        /// created through the Manager, so that the IInspectorManager->IInspectorDrawer->IInspector
        /// hierarchy can be properly set up.
        /// </summary>
        /// <typeparam name="TInspector"> Type of the inspector. </typeparam>
        /// <param name="result">[out]The created inspector</param>
        /// <param name="drawer"> The drawer of the inspector. </param>
        /// <param name="preferences"> Preferences for the inspector. </param>
        /// <param name="inspected"> The inspected Unity Objects. </param>
        /// <param name="scrollPos"> The current scroll position of the inspector. </param>
        /// <param name="viewIsLocked"> True if view is locked. </param>
        /// <param name="setup"> Delegate to the Setup method for the Inspector. </param>
        public void Create <TInspector>(out TInspector result, IInspectorDrawer drawer, InspectorPreferences preferences, Object[] inspected, Vector2 scrollPos, bool viewIsLocked, SetupForInspected <TInspector> setup) where TInspector : class, IInspector, new()
        {
            if (!pool.TryGet(out result))
            {
                result = new TInspector();
            }
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!activeInstances.Contains(result));
            Debug.Assert(!activeInstances.Contains(null));
                        #endif
            AddToActiveInstances(result);
            setup(result, preferences, drawer, inspected, scrollPos, viewIsLocked);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(activeInstances.Contains(result), "Created inspector " + result + " not found in InspectorManager.activeInstances");
            Debug.Assert(!pool.Contains(result), "Created inspector " + result + " still found in InspectorManager.pool");
                        #endif
        }
        public static void OnValidateCommand(this IInspectorDrawer inspectorDrawer, Event e)
        {
            if (DrawGUI.ExecutingCustomMenuCommand || !inspectorDrawer.HasFocus)
            {
                                #if DEV_MODE
                Debug.Log("Ignoring ValidateCommand with name: " + e.commandName);
                                #endif
                return;
            }

                        #if DEV_MODE
            Debug.Log("Detected ValidateCommand with name: " + e.commandName);
                        #endif

            var selectedView = inspectorDrawer.Manager.SelectedInspector;
            if (selectedView != null && selectedView.InspectorDrawer == inspectorDrawer && inspectorDrawer.HasFocus)
            {
                selectedView.OnValidateCommand(e);
            }
        }
Example #14
0
        /// <inheritdoc/>
        public void OnNextOnGUI(Action action, IInspectorDrawer changingInspectorDrawer = null)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(action != null);
                        #endif

                        #if DEV_MODE && DEBUG_ON_NEXT_ONGUI
            Debug.Log("OnNextOnGUI(" + StringUtils.ToString(action) + ") with changingInspectorDrawer=" + StringUtils.ToString(changingInspectorDrawer), changingInspectorDrawer as Object);
                        #endif

            DrawGUI.OnNextBeginOnGUI(action, false);

            if (changingInspectorDrawer != null)
            {
                changingInspectorDrawer.RefreshView();
            }
            else
            {
                EnsureOnGUICallbacks(false);
            }
        }
Example #15
0
        /// <inheritdoc/>
        public void OnNextLayout(Action action, IInspectorDrawer changingInspectorDrawer = null)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(action != null);
                        #endif

                        #if DEV_MODE && DEBUG_ON_NEXT_LAYOUT
            Debug.Log("OnNextLayout(" + StringUtils.ToString(action) + ")", changingInspectorDrawer as Object);
                        #endif

            onNextLayout += action;

            if (changingInspectorDrawer != null)
            {
                changingInspectorDrawer.RefreshView();
            }
            else
            {
                EnsureOnGUICallbacks(true);
            }
        }
Example #16
0
        public void OnInspectorDrawerLostFocus(IInspectorDrawer inspectorDrawer)
        {
            if (focusedDrawer != null)
            {
                if (inspector.InspectorDrawer == inspectorDrawer)
                {
                    focusedDrawer.OnInspectorLostFocusWhileSelected();

                    if (isMultiSelection)
                    {
                        for (int n = multiSelection.Count - 1; n >= 0; n--)
                        {
                            var multiSelected = multiSelection[n];
                            if (multiSelected != focusedDrawer)
                            {
                                multiSelected.OnInspectorLostFocusWhileSelected();
                            }
                        }
                    }
                }
            }
        }
        /// <summary> Deserialize inspector state. </summary>
        /// <param name="drawer"> The drawer of the inspector. </param>
        /// <param name="inspector">
        /// The inspector over which the state should be deserialized. If this is null, a new split view
        /// will be opened in the drawer, and state will be deserialized over that.
        /// </param>
        public void Deserialize(IInspectorDrawer drawer, [CanBeNull] IInspector inspector)
        {
                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log("Restoring state of " + inspector + " from " + inspected.Length + " int...");
                        #endif

            if (inspector == null)
            {
                var splittable = drawer as ISplittableInspectorDrawer;
                if (viewLocked)
                {
                    splittable.ShowInSplitView(Deserialize());
                }
                else
                {
                    splittable.SetSplitView(true);
                }
                inspector = splittable.SplitView;
            }
            else
            {
                inspector.State.ViewIsLocked = viewLocked;
                if (viewLocked)
                {
                    inspector.RebuildDrawers(Deserialize(), false);
                }
                else
                {
                    inspector.RebuildDrawersIfTargetsChanged();
                }
            }

            if (!string.IsNullOrEmpty(filter))
            {
                inspector.SetFilter(filter);
            }

            inspector.OnNextLayout(() => inspector.State.ScrollPos = scrollPos);
        }
Example #18
0
        internal static void UpdateDimensions(IInspectorDrawer inspectorDrawer, ISplittableInspectorDrawer splittable)
        {
            var inspectorWindowRect = inspectorDrawer.position;

            inspectorWindowRect.x = 0f;
            inspectorWindowRect.y = 0f;

            if (splittable != null && splittable.ViewIsSplit)
            {
                inspectorWindowRect.height *= 0.5f;

                var view = inspectorDrawer.MainView;
                view.State.UpdateDimensions(false, false, inspectorWindowRect, view.ToolbarHeight, view.PreviewAreaHeight);

                view = splittable.SplitView;
                if (view == null)
                {
                                        #if DEV_MODE
                    Debug.LogWarning("Splittable.ViewIsSplit was true but SplitView was null. Fixing now!");
                                        #endif
                    splittable.SetSplitView(true);
                    view = splittable.SplitView;
                                        #if DEV_MODE && PI_ASSERTATIONS
                    Debug.Assert(view != null, inspectorDrawer + " SplitView still null after calling SetSplitView(true)!");
                                        #endif
                }

                inspectorWindowRect.y += inspectorWindowRect.height;
                view.State.UpdateDimensions(false, false, inspectorWindowRect, view.ToolbarHeight, view.PreviewAreaHeight);
            }
            else
            {
                var view = inspectorDrawer.MainView;
                view.State.UpdateDimensions(false, false, inspectorWindowRect, view.ToolbarHeight, view.PreviewAreaHeight);
            }
        }
        public static void OnKeyDown(this IInspectorDrawer inspectorDrawer, Event e)
        {
                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(StringUtils.ToColorizedString(inspectorDrawer.ToString(), ".OnKeyDown(", e.keyCode, ") with HasFocus=", inspectorDrawer.HasFocus, ", selectedControl=", StringUtils.ToString(inspectorDrawer.SelectedOrDefaultView().FocusedDrawer), ", SelectedPart=", inspectorDrawer.Manager.SelectedInspectorPart));
                        #endif

            if (!inspectorDrawer.HasFocus)
            {
                return;
            }

            var view = inspectorDrawer.SelectedOrDefaultView();
            var keys = view.Preferences.keyConfigs;

                        #if !POWER_INSPECTOR_LITE
            if (keys.stepBackInSelectionHistory.DetectAndUseInput(e))
            {
                view.StepBackInSelectionHistory();
                return;
            }
            if (keys.stepForwardInSelectionHistory.DetectAndUseInput(e))
            {
                view.StepForwardInSelectionHistory();
                return;
            }
                        #endif

            inspectorDrawer.Repaint();

            DrawGUI.RegisterInputEvent(e);

            var activeView = inspectorDrawer.SelectedOrDefaultView();

            // give controls time to react to selection changes, editing text field changes etc.
            // before cached values are updated. (e.g. unapplied changes in delayed fields are
            // not discarded before they have time to get applied
            activeView.ResetNextUpdateCachedValues();

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(!inspectorDrawer.HasFocus || activeView.Selected);
                        #endif

                        #if DEV_MODE && DEBUG_KEYBOARD_INPUT
            Debug.Log(StringUtils.ToColorizedString("OnKeyDown activeView.Selected=", activeView.Selected, ", activeView.FocusedDrawer=", activeView.FocusedDrawer + ", Manager.SelectedInspector=", inspectorDrawer.Manager.SelectedInspector, ", inspectorDrawer.HasFocus=", inspectorDrawer.HasFocus));
                        #endif

            if (activeView.Toolbar.OnKeyboardInputGivenWhenNotSelected(e, activeView.Preferences.keyConfigs))
            {
                if (e.type != EventType.Used)
                {
                    DrawGUI.Use(e);
                    ExitGUIUtility.ExitGUI();
                }
            }

            IDrawer selectedControl = null;
            if (activeView.Selected)
            {
                selectedControl = activeView.FocusedDrawer;
                if (selectedControl != null)
                {
                    var onKeyboardInputBeingGiven = selectedControl.OnKeyboardInputBeingGiven;
                    if (onKeyboardInputBeingGiven != null)
                    {
                                                #if DEV_MODE && DEBUG_KEYBOARD_INPUT
                        Debug.Log("onKeyboardInputBeingGiven(" + StringUtils.ToString(e) + "): " + StringUtils.ToString(onKeyboardInputBeingGiven));
                                                #endif
                        if (onKeyboardInputBeingGiven(selectedControl, e, selectedControl.Inspector.Preferences.keyConfigs))
                        {
                            return;
                        }
                    }

                    if (selectedControl.OnKeyboardInputGiven(e, selectedControl.Inspector.Preferences.keyConfigs))
                    {
                        return;
                    }
                }
                else if (inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.Toolbar)
                {
                    activeView.Toolbar.OnKeyboardInputGiven(e, activeView.Preferences.keyConfigs);
                }
                else if (inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.Viewport || inspectorDrawer.Manager.SelectedInspectorPart == InspectorPart.None)
                {
                    bool fieldChangeInputGiven;
                    if (keys.DetectNextField(e, true) || keys.DetectPreviousField(e, true) ||
                        keys.nextFieldLeft.DetectAndUseInput(e) || keys.nextFieldRight.DetectAndUseInput(e) ||
                        keys.nextFieldDown.DetectAndUseInput(e) || keys.nextFieldUp.DetectAndUseInput(e))
                    {
                        fieldChangeInputGiven = true;
                    }
                    else if (e.modifiers == EventModifiers.FunctionKey)
                    {
                        switch (e.keyCode)
                        {
                        case KeyCode.DownArrow:
                        case KeyCode.UpArrow:
                        case KeyCode.LeftArrow:
                        case KeyCode.RightArrow:
                            fieldChangeInputGiven = true;
                            break;

                        default:
                            fieldChangeInputGiven = false;
                            break;
                        }
                    }
                    else
                    {
                        fieldChangeInputGiven = false;
                    }

                    if (fieldChangeInputGiven)
                    {
                        var drawers = activeView.State.drawers;
                        if (drawers.Length == 0)
                        {
                            if (activeView.Toolbar != null)
                            {
                                activeView.Toolbar.OnFindCommandGiven();
                            }
                            else
                            {
                                KeyboardControlUtility.SetKeyboardControl(0, 3);
                            }
                        }
                        else
                        {
                            var first  = drawers[0];
                            var select = first.GetNextSelectableDrawerRight(true, null);

                                                        #if DEV_MODE && DEBUG_NEXT_FIELD
                            Debug.Log(first + ".GetNextSelectableDrawerRight: " + StringUtils.ToString(select));
                                                        #endif

                            if (select != null)
                            {
                                activeView.Select(select, ReasonSelectionChanged.SelectNextControl);
                            }
                        }
                    }
                }
            }

            if (DrawGUI.EditingTextField && keys.DetectTextFieldReservedInput(e, TextFieldType.TextRow))
            {
                                #if DEV_MODE && DEBUG_KEYBOARD_INPUT
                Debug.Log(StringUtils.ToColorizedString("OnKeyboardInputGiven( ", StringUtils.ToString(e), ") DetectTextFieldReservedInput: ", true, " with selectedControl=", selectedControl));
                                #endif
                return;
            }

            if (keys.addComponent.DetectInput(e))
            {
                                #if DEV_MODE
                Debug.Log("AddComponent shortcut detected");
                                #endif

                if (AddComponentButtonDrawer.OpenSelectedOrFirstFoundInstance(activeView))
                {
                    DrawGUI.Use(e);
                }
            }

            if (keys.toggleSplitView.DetectInput(e))
            {
                var splittable = inspectorDrawer as ISplittableInspectorDrawer;
                if (splittable != null && splittable.CanSplitView)
                {
                    DrawGUI.Use(e);
                    bool setSplitView = !splittable.ViewIsSplit;
                    splittable.MainView.OnNextLayout(() => splittable.SetSplitView(setSplitView));
                }
            }

            if (keys.refresh.DetectAndUseInput(e))
            {
                var selectedInspector = inspectorDrawer.Manager.SelectedInspector;
                if (selectedInspector != null && selectedInspector.InspectorDrawer == inspectorDrawer)
                {
                    selectedInspector.ForceRebuildDrawers();
                }
                else
                {
                    var mainView = inspectorDrawer.MainView;
                    mainView.ForceRebuildDrawers();
                    var splittable = inspectorDrawer as ISplittableInspectorDrawer;
                    if (splittable != null && splittable.ViewIsSplit)
                    {
                        splittable.SplitView.ForceRebuildDrawers();
                    }
                }
            }

            var keyCode = e.keyCode;
            switch (keyCode)
            {
            case KeyCode.Menu:
                if (selectedControl != null)
                {
                    selectedControl.OpenContextMenu(e, selectedControl.RightClickArea, false, selectedControl.SelectedPart);
                }
                break;

            case KeyCode.Space:
                inspectorDrawer.Manager.RegisterKeyHeldDown(keyCode, "space");
                break;

            case KeyCode.F2:
                inspectorDrawer.Repaint();
                if (!DrawGUI.EditingTextField)
                {
                    DrawGUI.Use(e);
                    DrawGUI.EditingTextField = true;
                }
                break;

            case KeyCode.Escape:

                                        #if DEV_MODE
                Debug.Log("!!! ESCAPE !!!");
                                        #endif

                //when dragging a control, allow aborting using the escape key
                if (inspectorDrawer.Manager.MouseDownInfo.MouseDownOverDrawer != null)
                {
                    inspectorDrawer.Manager.MouseDownInfo.Clear();
                }

                if (DrawGUI.EditingTextField)
                {
                    DrawGUI.Use(e);
                    DrawGUI.EditingTextField = false;
                }
                break;

            case KeyCode.AltGr:
            case KeyCode.RightAlt:
                KeyConfig.OnAltGrDown();
                break;

                                #if DEV_MODE
            case KeyCode.I:
                if (e.control && e.alt)
                {
                    Debug.Log("INFO: FocusedDrawer=" + StringUtils.ToString(inspectorDrawer.SelectedOrDefaultView().FocusedDrawer) + ", EditingTextField=" + DrawGUI.EditingTextField);
                }
                break;
                                #endif
            }
        }
Example #20
0
 public IInspector Create(Type inspectorType, IInspectorDrawer drawer, InspectorPreferences preferences)
 {
     return(Create(inspectorType, drawer, preferences, ArrayPool <Object> .ZeroSizeArray, Vector2.zero, false));
 }
 public static bool IsPowerInspectorWindow(IInspectorDrawer test)
 {
     return(string.Equals(test.GetType().Name, "PowerInspectorWindow"));
 }
 private static PreferencesDrawer GetPrefencesDrawer(IInspectorDrawer preferencesWindow)
 {
     return(GetPrefencesDrawer(preferencesWindow.MainView));
 }
 public static void OnKeyUp(this IInspectorDrawer inspectorDrawer, Event e)
 {
     inspectorDrawer.Manager.OnKeyUp(e);
 }
Example #24
0
 /// <summary> Initializes the PowerInspector instance. </summary>
 /// <param name="inspector"> The inspector. </param>
 /// <param name="preferences"> inspector preferences. </param>
 /// <param name="drawer"> The drawer. </param>
 /// <param name="inspected"> The inspected targets. </param>
 /// <param name="scrollPos"> The viewport scroll position. </param>
 /// <param name="viewIsLocked"> True if view is locked. </param>
 public static void Setup(PowerInspector inspector, InspectorPreferences preferences, IInspectorDrawer drawer, Object[] inspected, Vector2 scrollPos, bool viewIsLocked)
 {
     inspector.Setup(drawer, preferences, inspected, scrollPos, viewIsLocked);
 }
Example #25
0
 public static void Setup([NotNull] SimpleInspector inspector, [NotNull] InspectorPreferences preferences, [NotNull] IInspectorDrawer drawer, [NotNull] Object[] inspected, Vector2 scrollPos, bool viewIsLocked)
 {
     inspector.Setup(drawer, preferences, inspected, scrollPos, viewIsLocked);
 }
Example #26
0
 public IInspector Create <TInspector>(IInspectorDrawer drawer, InspectorPreferences preferences) where TInspector : class, IInspector, new()
 {
     return(Create <TInspector>(drawer, preferences, ArrayPool <Object> .ZeroSizeArray, Vector2.zero, false));
 }
Example #27
0
        /// <summary>
        /// This should be called at the beginning of OnGUI of every instance of classes that implement IInspectorDrawer.
        ///
        /// SEE ALSO: DrawGUI.BeginOnGUI and InspectorUtility.BeginInspector.
        /// </summary>
        /// <param name="inspectorDrawer"> The inspector drawer instance. </param>
        /// <param name="splittable"> The inspector drawer if it implements ISplittableInspectorDrawer, otherwise null. </param>
        public static void BeginInspectorDrawer([NotNull] IInspectorDrawer inspectorDrawer, [CanBeNull] ISplittableInspectorDrawer splittable)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(inspectorDrawer != null);
                        #endif

            var manager = inspectorDrawer.Manager;
            activeInspectorDrawer         = inspectorDrawer;
            ActiveManager                 = manager;
            activeManager.ActiveInspector = inspectorDrawer.MainView;

            var e = Event.current;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(e != null);
                        #endif

            var mouseDownInfo = activeManager.MouseDownInfo;

            // Events like MouseUp, DragUpdated and DragPerformed are normally ignored when the cursor is outside EditorWindow bounds
            // but when a field is being dragged we still need those events (especially important for the MouseUp event!)
            var type = mouseDownInfo.GetEventTypeForMouseUpDetection(e);

            if (mouseDownInfo.NowReordering)
            {
                var reordering = mouseDownInfo.Reordering;

                var dropTarget = reordering.MouseoveredDropTarget;

                // When reordering and cursor is not above a valid drop target, set DragAndDropVisualMode to rejected,
                // unless dragging Object references outside window bounds, where want to allow dragging into other
                // EditorWindows.
                // UPDATE: This broke drag n drop e.g. from Component header to object reference field inside a custom editor.
                //if(dropTarget.Parent == null && ((DrawGUI.Active.DragAndDropObjectReferences.Length == 0 || activeManager.MouseoveredInspector != null)))
                if (dropTarget.Parent == null && DrawGUI.Active.DragAndDropObjectReferences.Length == 0)
                {
                                        #if DEV_MODE
                    Debug.LogWarning("Reordering Rejected because dropTarget.Parent=null && DrawGUI.Active.DragAndDropObjectReferences=" + StringUtils.ToString(DrawGUI.Active.DragAndDropObjectReferences) + ", activeManager.MouseoveredInspector=" + StringUtils.ToString(activeManager.MouseoveredInspector));
                                        #endif

                    // Update: only do this once cursor has moved, otherwise it can look strange during simple click events
                    if (mouseDownInfo.CursorMovedAfterMouseDown)
                    {
                        DrawGUI.Active.DragAndDropVisualMode = DragAndDropVisualMode.Rejected;
                    }
                }
                DrawGUI.Active.AddCursorRect(new Rect(0f, 0f, 100000f, 100000f), MouseCursor.MoveArrow);
            }
            else if (mouseDownInfo.NowDraggingPrefix)
            {
                DrawGUI.Active.SetCursor(MouseCursor.SlideArrow);
            }

            switch (type)
            {
            case EventType.Repaint:
                if (inspectorDrawer.MainView.RequiresConstantRepaint() || (splittable != null && splittable.ViewIsSplit && splittable.SplitView.RequiresConstantRepaint()))
                {
                    inspectorDrawer.Repaint();
                }
                break;

            case EventType.Layout:
                activeManager.OnLayout();
                UpdateDimensions(inspectorDrawer, splittable);
                break;

            case EventType.ValidateCommand:
                inspectorDrawer.OnValidateCommand(e);
                break;

            case EventType.ExecuteCommand:
                if (OnExecuteCommand != null)
                {
                    if (inspectorDrawer == manager.FirstInspectorDrawer)
                    {
                                                        #if DEV_MODE && DEBUG_EXECUTE_COMMAND
                        Debug.Log("ExecuteCommand(" + e.commandName + ")");
                                                        #endif
                        OnExecuteCommand(ActiveManager.LastSelectedActiveOrDefaultInspector(), e.commandName);
                    }
                                                #if DEV_MODE && DEBUG_EXECUTE_COMMAND
                    else
                    {
                        Debug.Log("ExecuteCommand(" + e.commandName + ") not sent with e=" + StringUtils.ToString(e) + ", OnExecuteCommand=" + StringUtils.ToString(OnExecuteCommand));
                    }
                                                #endif
                }
                inspectorDrawer.OnExecuteCommand(e);
                break;

            case EventType.MouseUp:
            case EventType.DragPerform:
                                        #if DEV_MODE && (DEBUG_MOUSE_UP || DEBUG_DRAG_N_DROP)
                Debug.Log(type + " with IsUnityObjectDrag=" + StringUtils.True + ", MouseDownInfo.Inspector=" + activeManager.MouseDownInfo.Inspector + ", activeInspectorDrawer.MouseIsOver=" + (inspectorDrawer == null ? StringUtils.Null : StringUtils.ToColorizedString(inspectorDrawer.MouseIsOver)));
                                        #endif
                inspectorDrawer.Repaint();
                mouseDownInfo.OnMouseUp(activeManager);
                break;

            case EventType.DragExited:
                //IMPORTANT NOTE: DragExited gets called when during DragNDrop cursor leaves EditorWindow bounds!
                                        #if DEV_MODE && UNITY_EDITOR
                Debug.Log(type + " with LastInputEvent().type=" + DrawGUI.LastInputEvent().type + ", IsUnityObjectDrag=" + StringUtils.ToColorizedString(DrawGUI.IsUnityObjectDrag) + ", EditorWindow.focusedWindow=" + UnityEditor.EditorWindow.focusedWindow + ", activeManager.MouseoveredInspector=" + activeManager.MouseoveredInspector + ", mouseoveredDrawer.position=" + (activeManager.MouseoveredInspector == null || activeManager.MouseoveredInspector.InspectorDrawer == null ? StringUtils.Null : activeManager.MouseoveredInspector.InspectorDrawer.position.ToString()) + ", MouseDownInfo.Inspector=" + activeManager.MouseDownInfo.Inspector + ", Drawer.MouseIsOver=" + (activeInspectorDrawer == null ? StringUtils.Null : StringUtils.ToColorizedString(activeInspectorDrawer.MouseIsOver)));
                                        #endif

                if (mouseDownInfo.IsDragExitedReallyMouseLeaveWindowEvent())
                {
                                                #if DEV_MODE
                    Debug.LogWarning("Ignoring DragExited call because IsDragExitedReallyMouseLeaveWindowEvent=" + StringUtils.True + " - cursor probably just left EditorWindow bounds.");
                                                #endif
                    break;
                }
                inspectorDrawer.Repaint();
                mouseDownInfo.OnMouseUp(activeManager);
                break;

            case EventType.MouseDown:
                ActiveManager.MouseDownInfo.OnMouseDown();
                                        #if DEV_MODE && DEBUG_ON_MOUSE_DOWN
                Debug.Log("MouseDown with button=" + e.button + ", keyCode=" + e.keyCode + ", MouseoveredSelectable=" + StringUtils.ToString(ActiveManager.MouseoveredSelectable));
                                        #endif
                break;

            case EventType.KeyDown:
                inspectorDrawer.OnKeyDown(e);
                break;

            case EventType.KeyUp:
                inspectorDrawer.Manager.OnKeyUp(e);
                break;
            }
        }
Example #28
0
        public void OnDisposing([NotNull] IInspector disposing)
        {
            if (lastSelectedInspector == disposing)
            {
                lastSelectedInspector = null;
            }

            var type = disposing.GetType();
            var lastSelectedInspectorOfSameType = GetLastSelectedInspector(type);

            if (lastSelectedInspectorOfSameType == disposing)
            {
                lastSelectedInspectors.Remove(type);
            }

            var inspectorDrawer = disposing.InspectorDrawer;

            if (inspectorDrawer != null)
            {
                if (inspectorDrawer.NowClosing)
                {
                                        #if DEV_MODE && DEBUG_DISPOSE
                    UnityEngine.Debug.Log("OnDisposing(" + disposing + "): NowClosing was " + StringUtils.True);
                                        #endif

                    var inspectorDrawerType         = inspectorDrawer.GetType();
                    var lastSelectedInspectorDrawer = GetLastSelectedInspectorDrawer(inspectorDrawerType);
                    if (lastSelectedInspectorDrawer == inspectorDrawer)
                    {
                                                #if DEV_MODE && DEBUG_DISPOSE
                        UnityEngine.Debug.Log("OnDisposing(" + disposing + "): removed " + inspectorDrawer.GetType().Name + " from lastSelectedInspectorDrawers");
                                                #endif
                        lastSelectedInspectorDrawers.Remove(inspectorDrawerType);
                    }

                                        #if UNITY_EDITOR
                    if (lastSelectedEditorWindow == inspectorDrawer)
                    {
                                                #if DEV_MODE && DEBUG_DISPOSE
                        UnityEngine.Debug.Log("OnDisposing(" + disposing + "): setting lastSelectedEditorWindow to null");
                                                #endif
                        lastSelectedEditorWindow = null;
                    }
                                        #endif
                }
                                #if DEV_MODE && DEBUG_DISPOSE
                else
                {
                    UnityEngine.Debug.Log("OnDisposing(" + disposing + "): NowClosing was " + StringUtils.False);
                }
                                #endif
            }
            else
            {
                                #if DEV_MODE && DEBUG_DISPOSE
                UnityEngine.Debug.Log("OnDisposing(" + disposing + "): inspectorDrawer was null!");
                                #endif

                CleanUpLastSelectedInspectorDrawers();
            }
        }
Example #29
0
        /// <summary>
        /// This should be called at the beginning of OnGUI of every instance of classes that implement IInspector.
        ///
        /// Handles things like setting the ActiveInspector, updating mouseovered inspector part, and broadcasting various events.
        ///
        /// SEE ALSO: DrawGUI.BeginOnGUI and InspectorUtility.BeginInspectorDrawer.
        /// </summary>
        public static void BeginInspector([NotNull] IInspector inspector, ref bool anyInspectorPartMouseovered)
        {
            inspectorBeginScreenPoint = GUIUtility.GUIToScreenPoint(Vector2.zero);
            GUISpace.Current          = Space.Window;

            activeInspectorDrawer = inspector.InspectorDrawer;
            ActiveManager         = activeInspectorDrawer.Manager;

                        #if DEV_MODE
            Debug.Assert(activeManager.ActiveInstances.Contains(inspector));
                        #endif

            var e = Event.current;

            var setMouseoveredPart = inspector.GetMouseoveredPartUpdated(ref anyInspectorPartMouseovered);
            if (setMouseoveredPart != InspectorPart.None)
            {
                inspector.InspectorDrawer.Manager.SetMouseoveredInspector(inspector, setMouseoveredPart);
            }
            else if (activeManager.MouseoveredInspector == inspector)
            {
                                #if DEV_MODE && DEBUG_SET_MOUSEOVERED_INSPECTOR
                Debug.Log(StringUtils.ToColorizedString("SetMouseoveredInspector(", StringUtils.Null, ") with anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", IgnoreAllMouseInputs=", activeManager.IgnoreAllMouseInputs, ", Cursor.CanRequestLocalPosition=", Cursor.CanRequestLocalPosition, ", Cursor.LocalPosition=", Cursor.LocalPosition, ", windowRect=", inspector.State.WindowRect));
                                #endif

                activeManager.SetMouseoveredInspector(null, InspectorPart.None);
            }

            activeManager.ActiveInspector = inspector;

            var state = inspector.State;

            inspector.NowDrawingPart = InspectorPart.Other;

            if (OnInspectorGUIBegin != null)
            {
                OnInspectorGUIBegin(inspector);
            }

            var mouseDownInfo = activeManager.MouseDownInfo;

            // Events like MouseUp, DragUpdated and DragPerformed are normally ignored when the cursor is outside EditorWindow bounds
            // but when a field is being dragged we still need those events (especially important for the MouseUp event!)
            var type = mouseDownInfo.GetEventTypeForMouseUpDetection(e);

            switch (type)
            {
            case EventType.MouseUp:
            case EventType.DragPerform:
            case EventType.DragExited:
                                        #if DEV_MODE && DEBUG_DRAG_N_DROP
                Debug.Log(StringUtils.ToColorizedString("BeginInspector: " + e.type + " with ObjectReferences=", DrawGUI.Active.DragAndDropObjectReferences, ", MouseDownEventWasUsed=", mouseDownInfo.MouseDownEventWasUsed, ", IgnoreAllMouseInputs=", activeManager.IgnoreAllMouseInputs, ", mouseoveredPart=", setMouseoveredPart, ", button=", Event.current.button + ", mouseDownInfo.Inspector=", mouseDownInfo.Inspector, ", MouseDownOverControl=", mouseDownInfo.MouseDownOverDrawer));
                                        #endif

                if (e.type == EventType.DragExited && mouseDownInfo.IsDragExitedReallyMouseLeaveWindowEvent())
                {
                                                #if DEV_MODE
                    Debug.LogWarning("Ignoring DragExited call because IsDragExitedReallyMouseLeaveWindowEvent=" + StringUtils.True + " - cursor probably just left EditorWindow bounds.");
                                                #endif
                    break;
                }

                var mouseoveredInspector = activeManager.MouseoveredInspector;

                if (!activeManager.IgnoreAllMouseInputs && mouseoveredInspector != null)
                {
                    if (e.type == EventType.DragPerform || (e.type == EventType.MouseUp && Event.current.button == 0))
                    {
                        mouseoveredInspector.LastInputTime = Platform.Time;

                        var reordering   = mouseDownInfo.Reordering;
                        var reorderingTo = reordering.MouseoveredDropTarget.Parent;
                        if (reorderingTo != null && !mouseDownInfo.IsClick)
                        {
                            reorderingTo.OnMemberDragNDrop(mouseDownInfo, DrawGUI.Active.DragAndDropObjectReferences);
                        }
                                                        #if DEV_MODE && DEBUG_DRAG_N_DROP
                        else
                        {
                            Debug.Log(StringUtils.ToColorizedString("Won't call OnMemberDragNDrop. reorderingTo=", reorderingTo, ", mouseDownInfo.IsClick=", mouseDownInfo.IsClick));
                        }
                                                        #endif
                    }
                                                #if DEV_MODE && DEBUG_DRAG_N_DROP
                    else
                    {
                        Debug.Log(StringUtils.ToColorizedString("Won't call OnMemberDragNDrop. currentEvent.type=", e.type, ", Event.current.button=", Event.current.button));
                    }
                                                #endif
                }
                                        #if DEV_MODE && DEBUG_DRAG_N_DROP
                else
                {
                    Debug.Log(StringUtils.ToColorizedString("Won't call OnMemberDragNDrop. IgnoreAllMouseInputs=", activeManager.IgnoreAllMouseInputs, ", setMouseoveredPart=", setMouseoveredPart));
                }
                                        #endif

                if (mouseDownInfo.Inspector == inspector)
                {
                    if (e.type != EventType.MouseUp || Event.current.button == 0)
                    {
                        if (mouseDownInfo.MouseDownOverDrawer != null)
                        {
                                                                #if DEV_MODE
                            if (!mouseDownInfo.IsClick && !mouseDownInfo.CursorMovedAfterMouseDown)
                            {
                                Debug.LogWarning("Calling OnMouseUpAfterDownOverControl with IsClick=" + StringUtils.False + ", but CursorMovedAfterMouseDown was also false. Bug?");
                            }
                                                                #endif

                            mouseDownInfo.MouseDownOverDrawer.OnMouseUpAfterDownOverControl(e, mouseDownInfo.IsClick);
                        }
                        mouseDownInfo.Clear(true);
                    }
                }
                break;

            case EventType.MouseDown:
                                        #if DEV_MODE && DEBUG_ON_MOUSE_DOWN
                Debug.Log(StringUtils.ToColorizedString("BeginInspector(" + inspector + ") - MouseDown with IgnoreAllMouseInputs=", activeManager.IgnoreAllMouseInputs, ", setMouseoveredPart=", setMouseoveredPart));
                                        #endif

                if (!activeManager.IgnoreAllMouseInputs && setMouseoveredPart != InspectorPart.None)
                {
                    inspector.LastInputTime = Platform.Time;
                    inspector.OnMouseDown(e);

                    //give controls time to react to selection changes, editing text field changes etc.
                    //before cached values are updated
                }
                break;

            case EventType.KeyDown:
                inspector.LastInputTime = Platform.Time;
                break;

            case EventType.ContextClick:
                if (!activeManager.IgnoreAllMouseInputs && setMouseoveredPart != InspectorPart.None)
                {
                    inspector.OnContextClick(e);
                }
                break;
            }

            if (state.keyboardControlLastFrame != KeyboardControlUtility.KeyboardControl)
            {
                state.previousKeyboardControl  = state.keyboardControlLastFrame;
                state.keyboardControlLastFrame = KeyboardControlUtility.KeyboardControl;

                                #if UNITY_EDITOR
                state.previousKeyboardControlRect = state.keyboardRectLastFrame;
                state.keyboardRectLastFrame       = KeyboardControlUtility.Info.KeyboardRect;
                                #endif
            }
        }
Example #30
0
    private void            MakeArrayGUI <T>         (SerializedProperty property, String displayName)
    {
        var ggg = new SerializedPropertyList <T>(property);

        _arrayGUI = new ArrayGUI <T>(displayName, () => ggg);
    }