예제 #1
0
        public SplittableInspectorDrawerSerializedState([NotNull] ISplittableInspectorDrawer window)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(window != null, "SplittableInspectorDrawerSerializedState constructor called with null window.");
            Debug.Assert(window.MainView != null);
            Debug.Assert(window.MainView.State != null);
                        #endif

            mainViewState = new InspectorSerializedState(window.MainView.State);
            if (window.ViewIsSplit)
            {
                                #if DEV_MODE && PI_ASSERTATIONS
                Debug.Assert(window != null);
                Debug.Assert(window.SplitView != null);
                Debug.Assert(window.SplitView.State != null);
                                #endif

                splitViewState = new InspectorSerializedState(window.SplitView.State);
            }
                        #if DEV_MODE && PI_ASSERTATIONS
            else
            {
                Debug.Assert(splitViewState == null);
            }
                        #endif

                        #if DONT_USE_ODIN_SERIALIZER
            viewIsSplit = window.ViewIsSplit;
                        #endif

                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log("Saving state of " + window.GetType().Name + "...\nmainView: " + StringUtils.ToString(mainViewState.Deserialize()) + "\nsplitView: " + (splitViewState == null ? "null" : StringUtils.ToString(splitViewState.Deserialize())));
                        #endif
        }
예제 #2
0
        public void Deserialize([NotNull] ISplittableInspectorDrawer drawer)
        {
                        #if DEV_MODE && DEBUG_ENABLED
            Debug.Log("Restoring state of " + drawer + "...\nmainView: " + StringUtils.ToString(mainViewState.Deserialize()) + "\nsplitView: " + (splitViewState == null ? "null" : StringUtils.ToString(splitViewState.Deserialize())));
                        #endif

            mainViewState.Deserialize(drawer, drawer.MainView);

                        #if DONT_USE_ODIN_SERIALIZER
            if (!viewIsSplit)
            {
                drawer.SetSplitView(false);
                return;
            }
                        #endif

            if (splitViewState != null)
            {
                mainViewState.Deserialize(drawer, drawer.ViewIsSplit ? drawer.SplitView : null);
            }
            else
            {
                drawer.SetSplitView(false);
            }
        }
예제 #3
0
        /// <inheritdoc/>
        protected override void Setup()
        {
            var calcSize = InspectorPreferences.Styles.LockButton.CalcSize(GUIContent.none);

            size = calcSize.x + 4f;

            var labels = inspector.Preferences.labels;

            enableLabel  = labels.EnableLockView;
            disableLabel = labels.DisableLockView;
            label        = inspector.State.ViewIsLocked ? disableLabel : enableLabel;

            splittableDrawer = inspector.InspectorDrawer as ISplittableInspectorDrawer;
        }
예제 #4
0
        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();
                }
            }
        }
예제 #5
0
        private void ShowInSplitView(ISplittableInspectorDrawer drawer, int itemIndex)
        {
            currentIndex = itemIndex;

            if (!drawer.ViewIsSplit)
            {
                if (InspectorUtility.IsSafeToChangeInspectorContents)
                {
                    ShowCurrentInSplitViewNow(drawer);
                }
                else
                {
                    drawer.MainView.OnNextLayout(() => ShowCurrentInSplitViewNow(drawer));
                }
            }
            else
            {
                var splitView = drawer.SplitView;
                if (history[currentIndex].ContentsMatch(splitView.State.inspected))
                {
                    return;
                }

                if (splitView.State.ViewIsLocked)
                {
                    if (InspectorUtility.IsSafeToChangeInspectorContents)
                    {
                        splitView.OnNextLayout(() => RebuildDrawerForCurrent(splitView));
                    }
                    else
                    {
                        RebuildDrawerForCurrent(splitView);
                    }
                }
                else
                {
                    IgnoreNextRecordRequest();
                    splitView.Select(history[currentIndex]);
                }
            }
        }
예제 #6
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);
            }
        }
예제 #7
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;
            }
        }
예제 #8
0
 /// <inheritdoc/>
 protected override void Setup()
 {
     labels           = inspector.Preferences.labels;
     splittableDrawer = inspector.InspectorDrawer as ISplittableInspectorDrawer;
 }
예제 #9
0
 private void ShowCurrentInSplitViewNow(ISplittableInspectorDrawer drawer)
 {
     IgnoreNextRecordRequest();
     drawer.ShowInSplitView(history[currentIndex]);
 }