Пример #1
0
        /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary>
        /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param>
        /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param>
        public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered)
        {
            UnityEngine.Profiling.Profiler.BeginSample("OnGUI");

                        #if DEV_MODE && DEBUG_CLICK
            var e = Event.current;
            if (e.rawType == EventType.MouseDown)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", e, ", e.type=", e.type, ", button=", e.button, ", mousePos=", e.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl));
            }
                        #endif

            //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity
            if (Preferences == null)
            {
                Preferences = GetPreferences();
            }

                        #if DEV_MODE && DEBUG_MOUSEOVERED_PART
            if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "´, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition));
            }
                        #endif

            InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered);

            Rect toolbarRect;
            Rect viewportRect;
            Rect previewAreaRect;
            GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect);

            // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            // by making sure all values that could affect it are restored back to normal
            // var indentLevelWas = EditorGUI.indentLevel;
                        #if UNITY_EDITOR
            var labelWidthWas = EditorGUIUtility.labelWidth;
                        #endif
            var matrixWas = GUI.matrix;

            var currentEvent = Event.current;
            switch (currentEvent.type)
            {
            case EventType.Layout:
                State.nextUpdateCachedValues--;
                if (State.nextUpdateCachedValues <= 0)
                {
                    UpdateCachedValuesFromFields();
                }
                OnCursorPositionOrLayoutChanged();
                break;

            case EventType.MouseMove:
            case EventType.MouseDrag:
            case EventType.DragUpdated:
                if (IgnoreViewportMouseInputs())
                {
                                                #if DEV_MODE
                    //Debug.Log("ignoring "+ currentEvent.type+"...");
                                                #endif
                    break;
                }

                OnCursorPositionOrLayoutChanged();
                InspectorDrawer.RefreshView();
                break;
            }

            bool dirty;
            try
            {
                dirty = DrawViewport(viewportRect);
            }
            catch (Exception e)
            {
                if (ExitGUIUtility.ShouldRethrowException(e))
                {
                    NowDrawingPart      = InspectorPart.None;
                    DrawGUI.IndentLevel = 0;
                                        #if UNITY_EDITOR
                    EditorGUIUtility.labelWidth = labelWidthWas;
                                        #endif
                    GUI.skin   = null;
                    GUI.matrix = matrixWas;
                    throw;
                }
                                #if DEV_MODE
                Debug.LogWarning(ToString() + " " + e);
                                #endif
                dirty = true;
            }

                        #if !POWER_INSPECTOR_LITE
            NowDrawingPart = InspectorPart.Toolbar;
            {
                Toolbar.Draw(toolbarRect);
            }
                        #endif
            NowDrawingPart = InspectorPart.Other;

            //TO DO: Move to EndInspector if these are needed?
            //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            //by making sure all values that could affect it are restored back to normal
            DrawGUI.IndentLevel = 0;
                        #if UNITY_EDITOR
            EditorGUIUtility.labelWidth = labelWidthWas;
                        #endif
            GUI.skin   = null;
            GUI.matrix = matrixWas;

            if (dirty)
            {
                InspectorDrawer.RefreshView();
            }

            InspectorUtility.EndInspector(this);

            UnityEngine.Profiling.Profiler.EndSample();
        }
Пример #2
0
        /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary>
        /// <param name="position"> Rect describing the size and position of the inspector. </param>
        /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary>
        /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param>
        /// <param name="scrollable"> True if inspector should be drawn as a scrollable view. This might be false e.g. if the inspector drawer handles creating the scroll view. </param>
        public void OnGUI(Rect position, bool anyInspectorPartMouseovered, bool scrollable)
        {
            UnityEngine.Profiling.Profiler.BeginSample("SimpleInspector.OnGUI");

                        #if DEV_MODE
            Debug.Assert(InspectorDrawer.Manager.ActiveInstances.Contains(this));
                        #endif

            InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered);

            var currentEvent = Event.current;
            switch (currentEvent.type)
            {
            case EventType.Layout:
                State.nextUpdateCachedValues--;
                if (State.nextUpdateCachedValues <= 0)
                {
                    UpdateCachedValuesFromFields();
                }

                OnCursorPositionOrLayoutChanged();
                break;

            case EventType.MouseMove:
            case EventType.MouseDrag:
            case EventType.DragUpdated:
                if (IgnoreViewportMouseInputs())
                {
                    break;
                }

                OnCursorPositionOrLayoutChanged();

                InspectorDrawer.RefreshView();
                break;
            }

            bool dirty = false;

            if (scrollable)
            {
                BeginScrollView(position);
            }

            if (DrawViewport())
            {
                dirty = true;
            }

            if (scrollable)
            {
                GUI.EndScrollView();
            }

            if (dirty)
            {
                InspectorDrawer.RefreshView();
            }

            InspectorUtility.EndInspector(this);

            UnityEngine.Profiling.Profiler.EndSample();
        }
Пример #3
0
        /// <summary> This should be called by the IInspectorDrawer of the inspector during every OnGUI event. </summary>
        /// <param name="inspectorDimensions"> The position and bounds for where the inspecto should be drawn. </param>
        /// <param name="anyInspectorPartMouseovered"> True if any inspector part is currently mouseovered. </param>
        public override void OnGUI(Rect inspectorDimensions, bool anyInspectorPartMouseovered)
        {
            UnityEngine.Profiling.Profiler.BeginSample("OnGUI");

                        #if DEV_MODE && DEBUG_CLICK
            var ev = Event.current;
            if (ev.rawType == EventType.MouseDown)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString() + " Event=", ev, ", e.type=", ev.type, ", button=", ev.button, ", mousePos=", ev.mousePosition, ", GUIUtility.hotControl=", GUIUtility.hotControl));
            }
                        #endif

                        #if DEV_MODE && PI_ASSERTATIONS
            if (inspectorDimensions.width <= 0f)
            {
                Debug.LogError(GetType().Name + ".OnGUI inspectorDimensions.width <= 0f: " + inspectorDimensions);
            }
                        #endif

            //this can happen e.g. if the preferences file gets reimported due to being altered outside of Unity
            if (Preferences == null)
            {
                Preferences = GetPreferences();
            }

                        #if DEV_MODE && DEBUG_MOUSEOVERED_PART
            if (State.drawer.VisibleMembers.Length > 0 && DrawGUI.IsUnityObjectDrag)
            {
                Debug.Log(StringUtils.ToColorizedString(ToString(), ".OnGUI with mouseoveredPart=", MouseoveredPart, ", Event=" + StringUtils.ToString(Event.current), ", ignoreAllMouseInputs=", InspectorDrawer.Manager.IgnoreAllMouseInputs, "´, ObjectPickerIsOpen=", ObjectPicker.IsOpen, ", anyInspectorPartMouseovered=", anyInspectorPartMouseovered, ", InspectorDrawer.MouseIsOver=", InspectorDrawer.MouseIsOver, ", DrawGUI.CanRequestMousePosition=", Cursor.CanRequestLocalPosition));
            }
                        #endif

            InspectorUtility.BeginInspector(this, ref anyInspectorPartMouseovered);

            Rect toolbarRect;
            Rect viewportRect;
            Rect previewAreaRect;
            GetDrawPositions(inspectorDimensions, out toolbarRect, out viewportRect, out previewAreaRect);

            // trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            // by making sure all values that could affect it are restored back to normal
            // var indentLevelWas = EditorGUI.indentLevel;
            var labelWidthWas = EditorGUIUtility.labelWidth;
            var matrixWas     = GUI.matrix;

            var currentEvent = Event.current;
            switch (currentEvent.type)
            {
            case EventType.Layout:
                State.nextUpdateCachedValues--;
                if (State.nextUpdateCachedValues <= 0)
                {
                    UpdateCachedValuesFromFields();
                }
                OnCursorPositionOrLayoutChanged();
                break;

            case EventType.MouseMove:
            case EventType.MouseDrag:
            case EventType.DragUpdated:
                if (IgnoreViewportMouseInputs())
                {
                                                #if DEV_MODE
                    //Debug.Log("ignoring "+ currentEvent.type+"...");
                                                #endif
                    break;
                }

                OnCursorPositionOrLayoutChanged();
                InspectorDrawer.RefreshView();
                break;
            }

            bool dirty;
            try
            {
                dirty = DrawViewport(viewportRect);
            }
            catch (Exception e)
            {
                if (ExitGUIUtility.ShouldRethrowException(e))
                {
                    NowDrawingPart              = InspectorPart.None;
                    DrawGUI.IndentLevel         = 0;
                    EditorGUIUtility.labelWidth = labelWidthWas;
                    GUI.skin   = null;
                    GUI.matrix = matrixWas;
                    throw;
                }
                                #if DEV_MODE
                Debug.LogWarning(ToString() + " " + e);
                                #endif

                // Always throw ExitGUI exception if exceptions were caught to avoid GUI Layout warnings.
                ExitGUIUtility.ExitGUI();
                return;
            }

                        #if !POWER_INSPECTOR_LITE
            NowDrawingPart = InspectorPart.Toolbar;
            {
                Toolbar.Draw(toolbarRect);

                                #if UNITY_2019_3_OR_NEWER
                Color lineColor;
                if (DrawGUI.IsProSkin)
                {
                    lineColor = Preferences.theme.ComponentSeparatorLine;
                }
                else
                {
                    lineColor = new Color32(153, 153, 153, 255);
                }
                var lineRect = toolbarRect;
                lineRect.height = 1f;
                lineRect.y      = toolbarRect.height;
                DrawGUI.DrawLine(lineRect, lineColor);
                                #endif
            }
                        #endif
            NowDrawingPart = InspectorPart.Other;

            try
            {
                if (DrawPreviewArea)
                {
                    NowDrawingPart = InspectorPart.PreviewArea;
                    {
                        previewDrawer.Draw(previewAreaRect);
                    }
                    NowDrawingPart = InspectorPart.Other;
                }
            }
                        #if DEV_MODE
            catch (ArgumentException e)            // GUILayout: Mismatched LayoutGroup.repaint
            {
                Debug.LogError(StringUtils.ToString(Event.current) + " " + e + "\nEvent=" + StringUtils.ToString(Event.current));
                        #else
            catch (ArgumentException)
            {
                        #endif
                // new test to avoid GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
                NowDrawingPart = InspectorPart.None;
                ExitGUIUtility.ExitGUI();
            }

            //TO DO: Move to EndInspector if these are needed?
            //trying to fix a bug where the default inspector layout gets wacky if both it and this window are open
            //by making sure all values that could affect it are restored back to normal
            DrawGUI.IndentLevel         = 0;
            EditorGUIUtility.labelWidth = labelWidthWas;
            GUI.skin   = null;
            GUI.matrix = matrixWas;

            if (dirty)
            {
                InspectorDrawer.RefreshView();
            }

            InspectorUtility.EndInspector(this);

            UnityEngine.Profiling.Profiler.EndSample();
        }