public void AddTooltipViews()
            {
                var allViews = new List <GUIViewProxy>();

                GUIViewDebuggerHelperProxy.GetViews(allViews);

                foreach (var tooltipView in allViews.Where(v => v.IsGUIViewAssignableTo(GUIViewProxy.tooltipViewType)))
                {
                    m_MaskData[tooltipView] = MaskViewData.CreateEmpty(MaskType.FullyUnmasked);
                }
            }
 public void AddParentFullyUnmasked(EditorWindow window)
 {
     m_MaskData[window.GetParent()] = MaskViewData.CreateEmpty(MaskType.FullyUnmasked);
 }
        public static MaskData GetViewsAndRects(IEnumerable <UnmaskedView> unmaskedViews, out bool foundAncestorProperty)
        {
            foundAncestorProperty = false;

            var allViews = new List <GUIViewProxy>();

            GUIViewDebuggerHelperProxy.GetViews(allViews);

            // initialize result
            var result           = new Dictionary <GUIViewProxy, MaskViewData>();
            var unmaskedControls = new Dictionary <GUIViewProxy, List <GUIControlSelector> >();
            var viewsWithWindows = new Dictionary <GUIViewProxy, HashSet <EditorWindow> >();

            foreach (var unmaskedView in unmaskedViews)
            {
                foreach (var view in GetMatchingViews(unmaskedView, allViews, viewsWithWindows))
                {
                    MaskViewData maskViewData;
                    if (!result.TryGetValue(view, out maskViewData))
                    {
                        result[view] = new MaskViewData()
                        {
                            rects = new List <Rect>(8), maskType = unmaskedView.m_MaskType, maskSizeModifier = unmaskedView.m_MaskSizeModifier
                        };
                    }

                    List <GUIControlSelector> controls;
                    if (!unmaskedControls.TryGetValue(view, out controls))
                    {
                        unmaskedControls[view] = controls = new List <GUIControlSelector>();
                    }

                    controls.AddRange(unmaskedView.m_UnmaskedControls);
                }
            }

            // validate input
            foreach (var viewWithWindow in viewsWithWindows)
            {
                if (viewWithWindow.Value.Count > 1)
                {
                    throw new ArgumentException(
                              string.Format(
                                  "Tried to get controls from multiple EditorWindows docked in the same location: {0}",
                                  string.Join(", ", viewWithWindow.Value.Select(w => w.GetType().Name).ToArray())
                                  ),
                              "unmaskedViews"
                              );
                }
            }

            // populate result
            var drawInstructions         = new List <IMGUIDrawInstructionProxy>(32);
            var namedControlInstructions = new List <IMGUINamedControlInstructionProxy>(32);
            var propertyInstructions     = new List <IMGUIPropertyInstructionProxy>(32);

            foreach (var viewRects in result)
            {
                // prevents null exception when repainting in case e.g., user has accidentally maximized view
                if (!viewRects.Key.isWindowAndRootViewValid)
                {
                    continue;
                }

                var unmaskedControlSelectors = unmaskedControls[viewRects.Key];
                if (unmaskedControlSelectors.Count == 0)
                {
                    continue;
                }

                // if the view refers to an InspectorWindow, flush the optimized GUI blocks so that Editor control rects will be updated
                HashSet <EditorWindow> windows;
                if (viewsWithWindows.TryGetValue(viewRects.Key, out windows) && windows.Count > 0)
                {
                    InspectorWindowProxy.DirtyAllEditors(windows.First());
                }

                // TODO: use actual selectors when API is in place
                GUIViewDebuggerHelperProxy.DebugWindow(viewRects.Key);

                viewRects.Key.RepaintImmediately();

                GUIViewDebuggerHelperProxy.GetDrawInstructions(drawInstructions);
                GUIViewDebuggerHelperProxy.GetNamedControlInstructions(namedControlInstructions);
                GUIViewDebuggerHelperProxy.GetPropertyInstructions(propertyInstructions);

                foreach (var controlSelector in unmaskedControls[viewRects.Key])
                {
                    Rect regionRect  = Rect.zero;
                    bool regionFound = false;
                    switch (controlSelector.selectorMode)
                    {
                    case GUIControlSelector.Mode.GUIContent:
                        var selectorContent = controlSelector.guiContent;
                        foreach (var instruction in drawInstructions)
                        {
                            if (AreEquivalent(instruction.usedGUIContent, selectorContent))
                            {
                                regionFound = true;
                                regionRect  = instruction.rect;
                            }
                        }
                        break;

                    case GUIControlSelector.Mode.GUIStyleName:
                        foreach (var instruction in drawInstructions)
                        {
                            if (instruction.usedGUIStyleName == controlSelector.guiStyleName)
                            {
                                regionFound = true;
                                regionRect  = instruction.rect;
                            }
                        }
                        break;

                    case GUIControlSelector.Mode.NamedControl:
                        foreach (var instruction in namedControlInstructions)
                        {
                            if (instruction.name == controlSelector.controlName)
                            {
                                regionFound = true;
                                regionRect  = instruction.rect;
                            }
                        }
                        break;

                    case GUIControlSelector.Mode.Property:
                        if (controlSelector.targetType == null)
                        {
                            continue;
                        }
                        var targetTypeName = controlSelector.targetType.AssemblyQualifiedName;
                        foreach (var instruction in propertyInstructions)
                        {
                            if (
                                instruction.targetTypeName == targetTypeName &&
                                instruction.path == controlSelector.propertyPath
                                )
                            {
                                regionFound = true;
                                regionRect  = instruction.rect;
                            }
                        }

                        if (!regionFound)
                        {
                            // Property instruction not found
                            // Let's see if we can find any of the ancestor instructions to allow the user to unfold
                            regionFound = FindAncestorPropertyRegion(controlSelector.propertyPath, targetTypeName,
                                                                     drawInstructions, propertyInstructions,
                                                                     ref regionRect);
                            foundAncestorProperty = regionFound;
                        }
                        break;

                    default:
                        Debug.LogErrorFormat(
                            "No method currently implemented for selecting using specified mode: {0}",
                            controlSelector.selectorMode
                            );
                        break;
                    }

                    if (regionFound)
                    {
                        if (viewRects.Value.maskSizeModifier == MaskSizeModifier.ExpandWidthToWholeWindow)
                        {
                            const int padding = 5;
                            regionRect.x     = padding;
                            regionRect.width = viewRects.Key.position.width - padding * 2;
                        }
                        viewRects.Value.rects.Add(regionRect);
                    }
                }

                GUIViewDebuggerHelperProxy.StopDebugging();
            }

            return(new MaskData(result));
        }