示例#1
0
        /// Get a bounding rectangle around all the widgets that have been added to this frame
        public Rect CalculateWidgetBounds()
        {
            if (mAutoLayoutNeedsUpdate)
            {
                AutoLayoutUpdate();
            }

            Rect?bounds = null;

            foreach (KeyValuePair <IWidget, IGuiPosition> widget in mWidgets)
            {
                if (widget.Key != null)
                {
                    Vector2 position     = widget.Value.GetPosition(widget.Key);
                    Vector2 size         = widget.Key.ExternalSize;
                    Rect    widgetBounds = new Rect(position.x, position.y, size.x, size.y);
                    if (bounds == null)
                    {
                        bounds = widgetBounds;
                    }
                    else
                    {
                        bounds = RectUtility.BoundingRect(widgetBounds, (Rect)bounds);
                    }
                }
            }

            if (bounds == null)
            {
                bounds = new Rect();
            }

            return((Rect)bounds);
        }
        private void DrawTrackingModeIndicator(Rect toolTipRect, int posInList)
        {
            Rect rowRect  = new Rect(toolTipRect.x, toolTipRect.y + posInList * listElementsHeight, toolTipRect.width, listElementsHeight);
            Rect iconRect = new Rect(rowRect.x, rowRect.y, listElementsHeight, listElementsHeight).ContractedBy(1.5f);

            RectUtility.DrawBracketsAroundRect(iconRect);
        }
示例#3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Rect optionsRect = RectUtility.SliceVertical(position, buttonsHeight, out position);

            if (typeNames == null)
            {
                RefreshTypeList(property);
            }

            //Draw type selection popup
            Rect popupRect = RectUtility.SliceHoriozntal(optionsRect, position.width - 25, out Rect menuPosition);

            selected = EditorGUI.IntPopup(popupRect, selected, typeNames, optionsValue);

            if (GUI.Button(RectUtility.SliceHoriozntal(menuPosition, 5, false), "...", EditorStyles.miniButtonRight)) //TODO: Add icon
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Inject"), false, OnInjectSelectedTypeSelected, property);
                menu.AddItem(new GUIContent("Refresh"), false, OnRefreshTypeListSelected, property);
                menu.DropDown(menuPosition);
            }

            //Draw property field
            EditorGUI.PropertyField(position, property, new GUIContent(property.displayName), true);
        }
示例#4
0
        public void IntersectionVerification()
        {
            Rect testRect1 = new Rect(0.0f, 0.0f, 1.0f, 1.0f);
            Rect testRect2 = new Rect(0.5f, 0.5f, 1.5f, 1.5f);

            Assert.AreEqual(new Rect(0.5f, 0.5f, 0.5f, 0.5f), RectUtility.Intersection(testRect1, testRect2));
            Assert.AreEqual(testRect1, RectUtility.Intersection(testRect1, testRect1));
        }
示例#5
0
        public void ContainsPointVerifivation()
        {
            Rect testRect1 = new Rect(0.0f, 0.0f, 30.0f, 30.0f);

            Assert.IsTrue(RectUtility.Contains(testRect1, new Vector2(1.0f, 1.0f)));                // Contains
            Assert.IsFalse(RectUtility.Contains(testRect1, new Vector2(30.0f, 10.0f)));             // Borders
            Assert.IsFalse(RectUtility.Contains(testRect1, new Vector2(31.0f, 15.0f)));             // Does not Contain
        }
示例#6
0
        public void OverlapsVerifivation()
        {
            Rect testRect1 = new Rect(32.0f, 0.0f, 32.0f, 36.0f);
            Rect testRect2 = new Rect(0.0f, 0.0f, 32.0f, 56.0f);
            Rect testRect3 = new Rect(1.0f, 1.0f, 1.0f, 1.0f);

            Assert.IsFalse(RectUtility.Overlaps(testRect1, testRect2), "Bordering rectangles should return false");             // Borders
            Assert.IsFalse(RectUtility.Overlaps(testRect1, testRect3), "Bordering rectangles should return false");             // No Overlap
            Assert.IsTrue(RectUtility.Overlaps(testRect2, testRect3), "Overlapping rectangles should return true");             // Overlaps
            Assert.IsTrue(RectUtility.Overlaps(testRect1, testRect1), "Overlapping rectangles should return true");             // Overlaps
        }
示例#7
0
 /// Valid location is defined as an attemptedReservation that doesn't overlap any reservedSpaces
 private static bool IsValidLocation(IEnumerable <Rect> reservedSpaces, Rect attemptedReservation)
 {
     foreach (Rect reservedSpace in reservedSpaces)
     {
         if (RectUtility.Overlaps(attemptedReservation, reservedSpace))
         {
             return(false);
         }
     }
     return(true);
 }
示例#8
0
    private bool IsWithinSelectionBounds(Transform unitTransform)
    {
        if (!isSelecting)
        {
            return(false);
        }

        var camera         = Camera.main;
        var viewportBounds = RectUtility.GetViewportBounds(camera, mousePosition1, Input.mousePosition);

        return(viewportBounds.Contains(camera.WorldToViewportPoint(unitTransform.position)));
    }
示例#9
0
        private bool CheckWorkspaceIsVisible()
        {
            var screenRect = new Rect(0, 0, Screen.width, Screen.height - TimelineViewBehaviour.Instance.CurrentHeight);

            var minBuffer = Mathf.Max(BackgroundPanel.Draggable.SnapGridSize, 20.0f);

            var panelRect = RectUtility.RectTransformToScreenSpace(BackgroundPanel.RectTransform);

            panelRect = RectUtility.CreateExpandedRect(panelRect, -minBuffer);

            return(panelRect.Overlaps(screenRect, true));
        }
示例#10
0
        public void ContainsVerifivation()
        {
            Rect testRect1 = new Rect(0.0f, 0.0f, 30.0f, 30.0f);
            Rect testRect2 = new Rect(10.0f, 10.0f, 10.0f, 10.0f);
            Rect testRect3 = new Rect(10.0f, 10.0f, 100.0f, 100.0f);
            Rect testRect4 = new Rect(-10.0f, 10.0f, 1.0f, 1.0f);

            Assert.IsTrue(RectUtility.Contains(testRect1, testRect2));              // Contains
            Assert.IsFalse(RectUtility.Contains(testRect1, testRect4));             // Outside
            Assert.IsFalse(RectUtility.Contains(testRect1, testRect3));             // Outside and smaller
            Assert.IsFalse(RectUtility.Contains(testRect2, testRect3));             // Smaller
            Assert.IsTrue(RectUtility.Contains(testRect3, testRect2));              // Borders
        }
示例#11
0
    private void OnGUI()
    {
        if (!selectionMode)
        {
            return;
        }

        if (isSelecting)
        {
            var rect = RectUtility.GetScreenRect(mousePosition1, Input.mousePosition);
            RectUtility.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f));
            RectUtility.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f));
        }
    }
示例#12
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GT_MinMaxRangeAttribute minMaxRangeAttr = attribute as GT_MinMaxRangeAttribute;
            Rect labelRect = RectUtility.SliceVertical(position, EditorGUIUtility.singleLineHeight, out Rect slidersRect);

            EditorGUI.LabelField(labelRect, minMaxRangeAttr.Name);
            SerializedProperty minSliderProp = property.serializedObject.FindProperty(property.propertyPath);

            if (property.Next(false))
            {
                SerializedProperty maxSliderProp = property;
                if (string.IsNullOrEmpty(maxSliderControlName))
                {
                    maxSliderControlName = "Slider_" + maxSliderProp.name;
                }


                if (minSliderProp.propertyType != maxSliderProp.propertyType)
                {
                    EditorGUI.HelpBox(position, "Properties type don't match", MessageType.Warning);
                    return;
                }


                Rect minSliderRect = RectUtility.SliceHoriozntal(slidersRect, 10, false); // make 10 pixel indent
                minSliderRect = RectUtility.SliceVertical(minSliderRect, EditorGUI.GetPropertyHeight(property), out Rect maxSliderRect);

                EditorGUI.BeginChangeCheck();
                DrawSlider(minSliderRect, minSliderProp, "Min", minMaxRangeAttr.Min, minMaxRangeAttr.Max);
                if (EditorGUI.EndChangeCheck())
                {
                    ChangeValue(minSliderProp, maxSliderProp, false);
                }

                EditorGUI.BeginChangeCheck();

                GUI.SetNextControlName(maxSliderControlName);
                DrawSlider(maxSliderRect, maxSliderProp, "Max", minMaxRangeAttr.Min, minMaxRangeAttr.Max);

                if ((EditorGUI.EndChangeCheck() && EditorGUIUtility.editingTextField == false) ||
                    GUI.GetNameOfFocusedControl() != maxSliderControlName)
                {
                    ChangeValue(minSliderProp, maxSliderProp);
                }
            }
        }
示例#13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            int propertiesCount = (attribute as GT_MultiPropertiesAttribute).PropertiesCount;

            position = RectUtility.SliceVertical(position, height - EditorGUIUtility.standardVerticalSpacing);
            Rect[][] spliteRects = RectUtility.Split(position, propertiesCount, 2, 5, 0);

            for (int i = 0; i < propertiesCount; i++)
            {
                EditorGUI.PrefixLabel(spliteRects[0][i], new GUIContent(property.displayName));
                EditorGUI.PropertyField(spliteRects[1][i], property, GUIContent.none);

                if (property.Next(false) == false)
                {
                    break;
                }
            }
        }
示例#14
0
        /// <summary>
        /// 自动优化,每一个视图,如果被上层的任意视图矩形区域完全覆盖,则自动SetActive(false),节省渲染开销
        /// </summary>
        void AutoOptimize()
        {
            SortViewListBySiblingIndex();

            var lastIndex = viewList.Count - 1;

            if (isAutoOptimize && lastIndex > -1)
            {
                viewList[lastIndex].SetActive(true);
                var lastRT = viewList[lastIndex].GetComponent <RectTransform>();
                //如果被它完全压住的窗口,则隐藏
                for (int i = 0; i < lastIndex; i++)
                {
                    var compareRT = viewList[i].GetComponent <RectTransform>();
                    if (RectUtility.Contains(lastRT.rect, compareRT.rect))
                    {
                        compareRT.gameObject.SetActive(false);
                    }
                }
            }
        }
示例#15
0
        public Vector2 SizeThumb(IGuiElement thumb)
        {
            if (thumb != mThumb)
            {
                throw new Exception("ProceduralSize is applying the SizeThumb function to the wrong widget (" + thumb.Name + ")");
            }

            float minHeight = 0.0f;

            if (thumb.Style != null)
            {
                // Keep the thumb graphic from overlapping itself
                minHeight = thumb.Style.NinePartScale.GetSizeDifference().y;
            }

            Vector2 result       = InternalSize;
            float   maxHeight    = result.y;
            Rect    widgetBounds = Frame.CalculateWidgetBounds();

            widgetBounds = RectUtility.BoundingRect(Vector2.zero, widgetBounds);
            float percentInView = Frame.InternalSize.y / widgetBounds.yMax;

            // If the entire frame fits, make sure we are viewing the top of the frame
            if (percentInView >= 1.0f)
            {
                Frame.ResetScroll();
            }
            // Refresh the frame to make sure the scrollbar's percent is again accurate,
            // but only if the bounds changed (as an optimization)
            if (mOldWidgetBounds != null && (Rect)mOldWidgetBounds != widgetBounds)
            {
                Refresh();
            }
            // Remember this run's bounds for next time
            mOldWidgetBounds = widgetBounds;
            result.y         = Mathf.Lerp(minHeight, maxHeight, percentInView);

            return(result);
        }
示例#16
0
        public void BoundingRectVerifivation()
        {
            Rect testRect1 = new Rect(0.0f, 0.0f, 30.0f, 30.0f);
            Rect testRect2 = new Rect(10.0f, 10.0f, 10.0f, 10.0f);

            Rect    testRect3 = new Rect(10.0f, 10.0f, 100.0f, 100.0f);
            Vector2 testPnt1  = new Vector2(0.0f, 0.0f);
            Vector2 testPnt2  = new Vector2(-100.0f, 100.0f);

            Rect bounds1 = RectUtility.BoundingRect(testRect1, testRect2);

            Assert.AreEqual(0.0f, bounds1.xMin);
            Assert.AreEqual(0.0f, bounds1.yMin);
            Assert.AreEqual(30.0f, bounds1.xMax);
            Assert.AreEqual(30.0f, bounds1.yMax);

            Rect bounds2 = RectUtility.BoundingRect(bounds1, testRect3);

            Assert.AreEqual(0.0f, bounds2.x);
            Assert.AreEqual(0.0f, bounds2.y);
            Assert.AreEqual(110.0f, bounds2.width);
            Assert.AreEqual(110.0f, bounds2.height);

            Rect bounds3 = RectUtility.BoundingRect(testPnt1, testRect2);

            Assert.AreEqual(0.0f, bounds3.x);
            Assert.AreEqual(0.0f, bounds3.y);
            Assert.AreEqual(20.0f, bounds3.width);
            Assert.AreEqual(20.0f, bounds3.height);

            Rect bounds4 = RectUtility.BoundingRect(testPnt2, testRect1);

            Assert.AreEqual(-100.0f, bounds4.x);
            Assert.AreEqual(0.0f, bounds4.y);
            Assert.AreEqual(130.0f, bounds4.width);
            Assert.AreEqual(100.0f, bounds4.height);
        }
示例#17
0
        // This will need to be implemented with a Quad-tree (or some analog) if
        //  this naive, O(n-squared) search implementation turns out to be too slow.
        public Rect NextPosition(IWidget widget, IEnumerable <Rect> reservedSpaces, Vector2 parentSize, IList <KeyValuePair <IWidget, IAutoLayout> > autolayoutWidgets)
        {
            Rect        attemptedReservation = new Rect(0.0f, 0.0f, widget.ExternalSize.x, widget.ExternalSize.y);
            List <Rect> validLocations       = new List <Rect>();

            // Best case is if this widget fits in the initial guess location (top left)
            if (IsValidLocation(reservedSpaces, attemptedReservation))
            {
                validLocations.Add(attemptedReservation);
            }

            // If widget doesn't fit in the initial guess, try to place it to the
            //  right of any reserved space.
            if (validLocations.Count == 0)
            {
                Rect parentSpace = new Rect(0.0f, 0.0f, parentSize.x, parentSize.y);
                foreach (Rect reservedSpace in reservedSpaces)
                {
                    attemptedReservation = new Rect(reservedSpace.x + reservedSpace.width,
                                                    reservedSpace.y,
                                                    widget.ExternalSize.x,
                                                    widget.ExternalSize.y);
                    if (RectUtility.Contains(parentSpace, attemptedReservation) &&
                        IsValidLocation(reservedSpaces, attemptedReservation))
                    {                     // n-squared
                        validLocations.Add(attemptedReservation);
                    }
                }
            }

            // If the widget didn't fit to the right of any reserved space, try under them
            // This search doesn't check against the parent space, so the reserved space can
            //  go off the bottom of that space
            if (validLocations.Count == 0)
            {
                foreach (Rect reservedSpace in reservedSpaces)
                {
                    attemptedReservation = new Rect(reservedSpace.x,
                                                    reservedSpace.y + reservedSpace.height,
                                                    widget.ExternalSize.x,
                                                    widget.ExternalSize.y);
                    if (IsValidLocation(reservedSpaces, attemptedReservation))
                    {                     // n-squared
                        validLocations.Add(attemptedReservation);
                    }
                }
            }

            // Find the best validLocation: Highest on Y and then furthest to the left.
            List <Rect> bestOnY      = new List <Rect>();
            float       lowestYValue = Mathf.Infinity;

            foreach (Rect validLocation in validLocations)
            {
                if (validLocation.y < lowestYValue)
                {
                    lowestYValue = validLocation.y;
                }
            }

            foreach (Rect validLocation in validLocations)
            {
                if (validLocation.y == lowestYValue)
                {
                    bestOnY.Add(validLocation);
                }
            }

            // Out of the valid locations that are best on Y, find the one that's furthest to the left
            float lowestXValue = Mathf.Infinity;

            foreach (Rect validLocation in bestOnY)
            {
                if (validLocation.x < lowestXValue)
                {
                    lowestXValue         = validLocation.x;
                    attemptedReservation = validLocation;
                }
            }

            mCachedPositions[widget] = new Vector2(attemptedReservation.x, attemptedReservation.y);
            if (widget.Style != null)
            {
                mCachedPositions[widget] += new Vector2(widget.Style.ExternalMargins.Left, widget.Style.ExternalMargins.Top);
            }
            return(attemptedReservation);
        }