Ejemplo n.º 1
0
        public static void AddMaskToView(GUIViewProxy view, VisualElement child)
        {
            // Since 2019.3(?), we must suppress input to the elements behind masks.
            // TODO Doesn't suppress everything, e.g. tooltips are shown still.
            child.RegisterCallback <MouseDownEvent>((e) => e.StopPropagation());
            child.RegisterCallback <MouseUpEvent>((e) => e.StopPropagation());
            child.RegisterCallback <MouseMoveEvent>((e) => e.StopPropagation());
            child.RegisterCallback <WheelEvent>((e) => e.StopPropagation());
            child.RegisterCallback <PointerDownEvent>((e) => e.StopPropagation());
            child.RegisterCallback <PointerUpEvent>((e) => e.StopPropagation());
            child.RegisterCallback <PointerMoveEvent>((e) => e.StopPropagation());
            child.RegisterCallback <KeyDownEvent>((e) => e.StopPropagation());
            child.RegisterCallback <KeyUpEvent>((e) => e.StopPropagation());

            if (view.IsDockedToEditor())
            {
                UIElementsHelper.Add(UIElementsHelper.GetVisualTree(view), child);
            }
            else
            {
                var viewVisualElement = UIElementsHelper.GetVisualTree(view);

                Debug.Assert(
                    viewVisualElement.Children().Count() == 2 &&
                    viewVisualElement.Children().Count(viewChild => viewChild is IMGUIContainer) == 1,
                    "Could not find the expected VisualElement structure"
                    );

                foreach (var visualElement in viewVisualElement.Children())
                {
                    if (!(visualElement is IMGUIContainer))
                    {
                        UIElementsHelper.Add(visualElement, child);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void AddMaskToView(GUIViewProxy view, VisualElement child)
        {
            if (view.IsDockedToEditor())
            {
                UIElementsHelper.Add(UIElementsHelper.GetVisualTree(view), child);
            }
            else
            {
                var viewVisualElement = UIElementsHelper.GetVisualTree(view);

                Debug.Assert(viewVisualElement.Children().Count() == 2 &&
                             viewVisualElement.Children().Count(viewChild => viewChild is IMGUIContainer) == 1,
                             "Could not find the expected VisualElement structure");

                foreach (var visualElement in viewVisualElement.Children())
                {
                    if (!(visualElement is IMGUIContainer))
                    {
                        UIElementsHelper.Add(visualElement, child);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public static void Mask(
            UnmaskedView.MaskData unmaskedViewsAndRegionsMaskData, Color maskColor,
            UnmaskedView.MaskData highlightedRegionsMaskData, Color highlightColor, Color blockedInteractionsColor, float highlightThickness
            )
        {
            Unmask();

            CopyMaskData(unmaskedViewsAndRegionsMaskData, s_UnmaskedViews);
            CopyMaskData(highlightedRegionsMaskData, s_HighlightedViews);

            List <GUIViewProxy> views = new List <GUIViewProxy>();

            GUIViewDebuggerHelperProxy.GetViews(views);

            foreach (var view in views)
            {
                if (!view.isValid)
                {
                    continue;
                }

                MaskViewData maskViewData;

                var viewRect = new Rect(0, 0, view.position.width, view.position.height);

                // mask everything except the unmasked view rects
                if (s_UnmaskedViews.TryGetValue(view, out maskViewData))
                {
                    List <Rect> rects       = maskViewData.rects;
                    var         maskedRects = GetNegativeSpaceRects(viewRect, rects);
                    foreach (var rect in maskedRects)
                    {
                        var mask = new VisualElement();
                        mask.style.backgroundColor = maskColor;
                        mask.SetLayout(rect);
                        AddMaskToView(view, mask);
                        s_Masks.Add(mask);
                    }

                    if (maskViewData.maskType == MaskType.BlockInteractions)
                    {
                        foreach (var rect in rects)
                        {
                            var mask = new VisualElement();
                            mask.style.backgroundColor = blockedInteractionsColor;
                            mask.SetLayout(rect);
                            AddMaskToView(view, mask);
                            s_Masks.Add(mask);
                        }
                    }
                }
                // mask the whole view
                else
                {
                    var mask = new VisualElement();
                    mask.style.backgroundColor = maskColor;
                    mask.SetLayout(viewRect);
                    AddMaskToView(view, mask);
                    s_Masks.Add(mask);
                }

                if (s_HighlightedViews.TryGetValue(view, out maskViewData))
                {
                    var rects = maskViewData.rects;
                    // unclip highlight to apply as "outer stroke" if it is being applied to some control(s) in the view
                    var unclip       = rects.Count > 1 || rects[0] != viewRect;
                    var borderRadius = 5.0f;
                    foreach (var rect in rects)
                    {
                        var highlighter = new VisualElement();
#if UNITY_2019_3_OR_NEWER
                        highlighter.style.borderLeftColor   = highlightColor;
                        highlighter.style.borderRightColor  = highlightColor;
                        highlighter.style.borderTopColor    = highlightColor;
                        highlighter.style.borderBottomColor = highlightColor;
#else
                        highlighter.style.borderColor = highlightColor;
#endif
                        highlighter.style.borderLeftWidth   = highlightThickness;
                        highlighter.style.borderRightWidth  = highlightThickness;
                        highlighter.style.borderTopWidth    = highlightThickness;
                        highlighter.style.borderBottomWidth = highlightThickness;

                        highlighter.style.borderBottomLeftRadius  = borderRadius;
                        highlighter.style.borderTopLeftRadius     = borderRadius;
                        highlighter.style.borderBottomRightRadius = borderRadius;
                        highlighter.style.borderTopRightRadius    = borderRadius;

                        highlighter.pickingMode = PickingMode.Ignore;
                        var layout = rect;
                        if (unclip)
                        {
                            layout.xMin -= highlightThickness;
                            layout.xMax += highlightThickness;
                            layout.yMin -= highlightThickness;
                            layout.yMax += highlightThickness;
                        }
                        highlighter.SetLayout(layout);
                        UIElementsHelper.Add(UIElementsHelper.GetVisualTree(view), highlighter);
                        s_Highlighters.Add(highlighter);
                    }
                }
            }

            s_LastHighlightTime = EditorApplication.timeSinceStartup;
        }