void DoWindowPopup()
        {
            string selectedName = inspected == null ? Styles.defaultWindowPopupText : GetViewName(inspected);

            GUILayout.Label(Styles.inspectedWindowLabel, GUILayout.ExpandWidth(false));

            Rect popupPosition = GUILayoutUtility.GetRect(GUIContent.Temp(selectedName), EditorStyles.toolbarDropDown, GUILayout.ExpandWidth(true));

            if (GUI.Button(popupPosition, GUIContent.Temp(selectedName), EditorStyles.toolbarDropDown))
            {
                List <GUIView> views = new List <GUIView>();
                GUIViewDebuggerHelper.GetViews(views);

                List <GUIContent> options = new List <GUIContent>(views.Count + 1);

                options.Add(EditorGUIUtility.TrTextContent("None"));

                int            selectedIndex   = 0;
                List <GUIView> selectableViews = new List <GUIView>(views.Count + 1);
                for (int i = 0; i < views.Count; ++i)
                {
                    GUIView view = views[i];

                    //We can't inspect ourselves, otherwise we get infinite recursion.
                    //Also avoid the InstructionOverlay
                    if (!CanInspectView(view))
                    {
                        continue;
                    }

                    GUIContent label = new GUIContent(string.Format("{0}. {1}", options.Count, GetViewName(view)));
                    options.Add(label);
                    selectableViews.Add(view);

                    if (view == inspected)
                    {
                        selectedIndex = selectableViews.Count;
                    }
                }
                //TODO: convert this to a Unity Window style popup. This way we could highlight the window on hover ;)
                EditorUtility.DisplayCustomMenu(popupPosition, options.ToArray(), selectedIndex, OnWindowSelected, selectableViews);
            }
        }
Ejemplo n.º 2
0
        static Rect GetRectOfFieldInInspector(string fieldPathInClass, Type targetType, out bool found)
        {
            string viewName = nameof(InspectorWindow);
            var    allViews = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(allViews);

            var propertyInstructions = new List <IMGUIPropertyInstruction>(32);

            foreach (var view in allViews)
            {
                if (view.GetViewName() != viewName)
                {
                    continue;
                }                                                 //todo: we should have a way to reference the window without using its name

                GUIViewDebuggerHelper.DebugWindow(view);
                view.RepaintImmediately();
                GUIViewDebuggerHelper.GetPropertyInstructions(propertyInstructions);
                var targetTypeName = targetType.AssemblyQualifiedName;

                foreach (var instruction in propertyInstructions) //todo: we should have a way to reference hierarchy objects without using their names
                {
                    if (instruction.targetTypeName == targetTypeName &&
                        instruction.path == fieldPathInClass)
                    {
                        found = true;
                        return(instruction.rect);
                    }
                }
                var drawInstructions = new List <IMGUIDrawInstruction>(32);
                GUIViewDebuggerHelper.GetDrawInstructions(drawInstructions);

                // Property instruction not found
                // Let's see if we can find any of the ancestor instructions to allow the user to unfold
                Rect regionRect = new Rect();
                found = FindAncestorPropertyRegion(fieldPathInClass, targetTypeName, drawInstructions, propertyInstructions, ref regionRect);
                return(regionRect);
            }
            found = false;
            return(Rect.zero);
        }
Ejemplo n.º 3
0
        private void DoWindowPopup()
        {
            string t = "<Please Select>";

            if (this.m_Inspected != null)
            {
                t = GetViewName(this.m_Inspected);
            }
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(false) };
            GUILayout.Label("Inspected Window: ", options);
            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            Rect position = GUILayoutUtility.GetRect(GUIContent.Temp(t), EditorStyles.toolbarDropDown, optionArray2);

            if (GUI.Button(position, GUIContent.Temp(t), EditorStyles.toolbarDropDown))
            {
                List <GUIView> views = new List <GUIView>();
                GUIViewDebuggerHelper.GetViews(views);
                List <GUIContent> list2 = new List <GUIContent>(views.Count + 1)
                {
                    new GUIContent("None")
                };
                int            selected = 0;
                List <GUIView> userData = new List <GUIView>(views.Count + 1);
                for (int i = 0; i < views.Count; i++)
                {
                    GUIView view = views[i];
                    if (this.CanInspectView(view))
                    {
                        GUIContent item = new GUIContent(list2.Count + ". " + GetViewName(view));
                        list2.Add(item);
                        userData.Add(view);
                        if (view == this.m_Inspected)
                        {
                            selected = userData.Count;
                        }
                    }
                }
                EditorUtility.DisplayCustomMenu(position, list2.ToArray(), selected, new EditorUtility.SelectMenuItemFunction(this.OnWindowSelected), userData);
            }
        }
Ejemplo n.º 4
0
        private void DoWindowPopup()
        {
            string t = (!(this.inspected == null)) ? GUIViewDebuggerWindow.GetViewName(this.inspected) : GUIViewDebuggerWindow.Styles.defaultWindowPopupText;

            GUILayout.Label(GUIViewDebuggerWindow.Styles.inspectedWindowLabel, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(false)
            });
            Rect rect = GUILayoutUtility.GetRect(GUIContent.Temp(t), EditorStyles.toolbarDropDown, new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true)
            });

            if (GUI.Button(rect, GUIContent.Temp(t), EditorStyles.toolbarDropDown))
            {
                List <GUIView> list = new List <GUIView>();
                GUIViewDebuggerHelper.GetViews(list);
                List <GUIContent> list2 = new List <GUIContent>(list.Count + 1);
                list2.Add(EditorGUIUtility.TrTextContent("None", null, null));
                int            selected = 0;
                List <GUIView> list3    = new List <GUIView>(list.Count + 1);
                for (int i = 0; i < list.Count; i++)
                {
                    GUIView gUIView = list[i];
                    if (this.CanInspectView(gUIView))
                    {
                        GUIContent item = new GUIContent(string.Format("{0}. {1}", list2.Count, GUIViewDebuggerWindow.GetViewName(gUIView)));
                        list2.Add(item);
                        list3.Add(gUIView);
                        if (gUIView == this.inspected)
                        {
                            selected = list3.Count;
                        }
                    }
                }
                EditorUtility.DisplayCustomMenu(rect, list2.ToArray(), selected, new EditorUtility.SelectMenuItemFunction(this.OnWindowSelected), list3);
            }
        }
        private void OnWindowSelected(object userdata, string[] options, int selected)
        {
            --selected;
            GUIView guiView = selected < 0 ? (GUIView)null : ((List <GUIView>)userdata)[selected];

            if ((UnityEngine.Object) this.m_Inspected != (UnityEngine.Object)guiView)
            {
                if ((UnityEngine.Object) this.m_InstructionOverlayWindow != (UnityEngine.Object)null)
                {
                    this.m_InstructionOverlayWindow.Close();
                }
                this.m_Inspected = guiView;
                if ((UnityEngine.Object) this.m_Inspected != (UnityEngine.Object)null)
                {
                    GUIViewDebuggerHelper.DebugWindow(this.m_Inspected);
                    this.m_Inspected.Repaint();
                }
                this.m_ListViewState.row = -1;
                this.m_ListViewState.selectionChanged = true;
                this.m_Instruction = (GUIViewDebuggerWindow.GUIInstruction)null;
            }
            this.Repaint();
        }
Ejemplo n.º 6
0
 private void ShowDrawInstructions()
 {
     if (this.m_Inspected != null)
     {
         this.m_ListViewState.totalRows = GUIViewDebuggerHelper.GetInstructionCount();
         if (this.m_QueuedPointInspection)
         {
             this.m_ListViewState.row = this.FindInstructionUnderPoint(this.m_PointToInspect);
             this.m_ListViewState.selectionChanged = true;
             this.m_QueuedPointInspection          = false;
             this.m_Instruction.Reset();
         }
         SplitterGUILayout.BeginHorizontalSplit(this.m_InstructionListDetailSplitter, new GUILayoutOption[0]);
         this.DrawInstructionList();
         EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
         if (this.m_ListViewState.selectionChanged)
         {
             this.OnSelectedInstructionChanged();
         }
         this.DrawSelectedInstructionDetails();
         EditorGUILayout.EndVertical();
         SplitterGUILayout.EndHorizontalSplit();
     }
 }
Ejemplo n.º 7
0
 public override void UpdateInstructions()
 {
     //TODO: find a better approach instead of getting the whole list everyframe.
     m_PropertyList.Clear();
     GUIViewDebuggerHelper.GetPropertyInstructions(m_PropertyList);
 }
Ejemplo n.º 8
0
 public override void UpdateInstructions()
 {
     this.m_NamedControlInstructions.Clear();
     GUIViewDebuggerHelper.GetNamedControlInstructions(this.m_NamedControlInstructions);
 }
Ejemplo n.º 9
0
        /* todo: the following method seems to behave differently for properties representing Arrays, compared to how it behaves for non-array properties.
         * What happens is that regionRect becomes the "wrong side" of the property in the inspector */
        static bool FindAncestorPropertyRegion(string propertyPath, string targetTypeName,
                                               List <IMGUIDrawInstruction> drawInstructions, List <IMGUIPropertyInstruction> propertyInstructions,
                                               ref Rect regionRect)
        {
            while (true)
            {
                // Remove last component of property path
                var lastIndexOfDelimiter = propertyPath.LastIndexOf(".");
                if (lastIndexOfDelimiter < 1)
                {
                    // No components left, give up
                    return(false);
                }
                propertyPath = propertyPath.Substring(0, lastIndexOfDelimiter);
                foreach (var instruction in propertyInstructions)
                {
                    if (instruction.targetTypeName != targetTypeName || instruction.path != propertyPath)
                    {
                        continue;
                    }
                    regionRect = instruction.rect;

                    // The property rect itself does not contain the foldout arrow
                    // Expand region to include all draw instructions for this property
                    var unifiedInstructions = new List <IMGUIInstruction>(128);
                    GUIViewDebuggerHelper.GetUnifiedInstructions(unifiedInstructions);
                    var collectDrawInstructions = false;
                    var propertyBeginLevel      = 0;
                    foreach (var unifiedInstruction in unifiedInstructions)
                    {
                        if (collectDrawInstructions)
                        {
                            if (unifiedInstruction.level <= propertyBeginLevel)
                            {
                                break;
                            }
                            if (unifiedInstruction.type != InstructionType.kStyleDraw)
                            {
                                continue;
                            }

                            var drawRect = drawInstructions[unifiedInstruction.typeInstructionIndex].rect;
                            if (drawRect.xMin < regionRect.xMin)
                            {
                                regionRect.xMin = drawRect.xMin;
                            }
                            if (drawRect.yMin < regionRect.yMin)
                            {
                                regionRect.yMin = drawRect.yMin;
                            }
                            if (drawRect.xMax > regionRect.xMax)
                            {
                                regionRect.xMax = drawRect.xMax;
                            }
                            if (drawRect.yMax > regionRect.yMax)
                            {
                                regionRect.yMax = drawRect.yMax;
                            }
                        }
                        else
                        {
                            if (unifiedInstruction.type != InstructionType.kPropertyBegin)
                            {
                                continue;
                            }

                            var propertyInstruction = propertyInstructions[unifiedInstruction.typeInstructionIndex];
                            if (propertyInstruction.targetTypeName == targetTypeName &&
                                propertyInstruction.path == propertyPath)
                            {
                                collectDrawInstructions = true;
                                propertyBeginLevel      = unifiedInstruction.level;
                            }
                        }
                    }

                    return(true);
                }
            }
        }
 public override void UpdateInstructions()
 {
     m_Instructions.Clear();
     GUIViewDebuggerHelper.GetDrawInstructions(m_Instructions);
 }
Ejemplo n.º 11
0
 internal static void GetClipInstructions(List <IMGUIClipInstruction> clipInstructions)
 {
     GUIViewDebuggerHelper.GetClipInstructionsInternal(clipInstructions);
 }
Ejemplo n.º 12
0
 public override void UpdateInstructions()
 {
     this.m_PropertyList.Clear();
     GUIViewDebuggerHelper.GetPropertyInstructions(this.m_PropertyList);
 }
Ejemplo n.º 13
0
 private void OnDisable()
 {
     GUIViewDebuggerHelper.onViewInstructionsChanged = (Action)Delegate.Remove(GUIViewDebuggerHelper.onViewInstructionsChanged, new Action(this.OnInspectedViewChanged));
     GUIViewDebuggerHelper.StopDebugging();
     this.ClearInstructionHighlighter();
 }
 protected override int GetInstructionCount() =>
 GUIViewDebuggerHelper.GetInstructionCount();
Ejemplo n.º 15
0
 protected override int GetInstructionCount()
 {
     return(GUIViewDebuggerHelper.GetInstructionCount());
 }
Ejemplo n.º 16
0
 internal override void OnDoubleClickInstruction(int index)
 {
     this.ShowInstructionInExternalEditor(GUIViewDebuggerHelper.GetManagedStackTrace(index));
 }
Ejemplo n.º 17
0
        private void UpdateExploredGUIStyle(Vector2 screenPos)
        {
            GUIView mouseUnderView = GetViewUnderMouse(screenPos, m_ExploredViews);

            ExploredDrawInstructionIndex = -1;
            ExploredStyle = null;
            if (mouseUnderView != m_ExploredView)
            {
                if (m_ExploredView)
                {
                    GUIViewDebuggerHelper.StopDebugging();
                    // Debug.Log("Stop debugging: " + GetViewName(m_ExploredView));
                }

                m_ExploredView = CanInspectView(mouseUnderView) ? mouseUnderView : null;

                if (m_ExploredView)
                {
                    // Start debugging
                    GUIViewDebuggerHelper.DebugWindow(m_ExploredView);
                    // Debug.Log("Start debugging: " + GetViewName(m_ExploredView));

                    // Since we have attached the debugger, this view hasn't logged its repaint steps yet.
                    m_ExploredView.Repaint();
                }
            }

            if (m_ExploredView)
            {
                var drawInstructions = new List <IMGUIDrawInstruction>();
                GUIViewDebuggerHelper.GetDrawInstructions(drawInstructions);

                var localPosition = new Vector2(screenPos.x - mouseUnderView.screenPosition.x,
                                                screenPos.y - mouseUnderView.screenPosition.y);
                GUIStyle mouseUnderStyle = null;

                /** Note: no perfect way to find the style under cursor:
                 *  - Lots of style rect overlap
                 *  - by starting with the end, we hope to follow the "Last drawn instruction is the one on top"
                 *  - Some styles are "transparent" and drawn last (TabWindowBackground and such)
                 *  - We try to go with the smallest rect that fits
                 */
                Rect styleRect        = new Rect(0, 0, 10000, 10000);
                var  smallestRectArea = styleRect.width * styleRect.height;
                for (var i = drawInstructions.Count - 1; i >= 0; --i)
                {
                    var instr = drawInstructions[i];
                    if (instr.rect.Contains(localPosition) && smallestRectArea > instr.rect.width * instr.rect.height)
                    {
                        mouseUnderStyle              = instr.usedGUIStyle;
                        styleRect                    = instr.rect;
                        smallestRectArea             = instr.rect.width * instr.rect.height;
                        ExploredDrawInstructionIndex = i;

                        // Debug.Log(GetViewName(m_ExploredView) + " - Found Style: " + instr.usedGUIStyle.name);
                    }
                }

                if (Highlighter != null && mouseUnderStyle != null)
                {
                    var visualElement = m_ExploredView.windowBackend.visualTree as VisualElement;
                    if (visualElement != null)
                    {
                        // Debug.Log(GetViewName(m_ExploredView) + " - Highlight Style: " + mouseUnderStyle.name);
                        Highlighter.HighlightElement(visualElement, styleRect, mouseUnderStyle);
                    }
                }

                ExploredStyle = mouseUnderStyle;
            }
        }
Ejemplo n.º 18
0
 internal static void GetUnifiedInstructions(List <IMGUIInstruction> layoutInstructions)
 {
     GUIViewDebuggerHelper.GetUnifiedInstructionsInternal(layoutInstructions);
 }
Ejemplo n.º 19
0
 public override void UpdateInstructions()
 {
     this.m_ClipList.Clear();
     GUIViewDebuggerHelper.GetClipInstructions(this.m_ClipList);
 }
Ejemplo n.º 20
0
 internal static void GetViews(List <GUIView> views)
 {
     GUIViewDebuggerHelper.GetViewsInternal(views);
 }
 public override void UpdateInstructions()
 {
     this.m_LayoutInstructions.Clear();
     GUIViewDebuggerHelper.GetLayoutInstructions(this.m_LayoutInstructions);
 }