示例#1
0
        int FindInstructionUnderPoint(Vector2 point)
        {
            List <IMGUIDrawInstruction> drawInstructions = new List <IMGUIDrawInstruction>();

            GUIViewDebuggerHelper.GetDrawInstructions(drawInstructions);
            for (int i = 0; i < drawInstructions.Count; ++i)
            {
                Rect rect = drawInstructions[i].rect;
                if (rect.Contains(point))
                {
                    return(i);
                }
            }
            return(-1);
        }
示例#2
0
        static Rect GetRectOfObjectInGUIView(string viewName, UnityEngine.Object objectToFind, out bool found)
        {
            var allViews = new List <GUIView>();

            GUIViewDebuggerHelper.GetViews(allViews);

            var drawInstructions = new List <IMGUIDrawInstruction>(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.GetDrawInstructions(drawInstructions);
                foreach (var drawInstruction in drawInstructions) //todo: we should have a way to reference hierarchy objects without using their names
                {
                    //If we can reference the object represented by the draw instruction, we can find it like this

                    /*if (drawInstruction.usedGUIContent.representedObject != null)
                     * {
                     *  if (drawInstruction.usedGUIContent.representedObject == objectToFind)
                     *  {
                     *      found = true;
                     *      return drawInstruction.rect;
                     *  }
                     * }*/

                    if (drawInstruction.usedGUIContent.text != objectToFind.name)
                    {
                        continue;
                    }
                    found = true;
                    return(drawInstruction.rect);
                }
                found = false;
                return(Rect.zero);
            }
            found = false;
            return(Rect.zero);
        }
示例#3
0
        private int FindInstructionUnderPoint(Vector2 point)
        {
            List <IMGUIDrawInstruction> list = new List <IMGUIDrawInstruction>();

            GUIViewDebuggerHelper.GetDrawInstructions(list);
            int result;

            for (int i = 0; i < list.Count; i++)
            {
                Rect rect = list[i].rect;
                if (rect.Contains(point))
                {
                    result = i;
                    return(result);
                }
            }
            result = -1;
            return(result);
        }
示例#4
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);
        }
 public override void UpdateInstructions()
 {
     m_Instructions.Clear();
     GUIViewDebuggerHelper.GetDrawInstructions(m_Instructions);
 }
示例#6
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;
            }
        }