Example #1
0
        private void LayoutCreateRange(Rect rect, float angleOffset, float radius)
        {
            if (Event.current.type == EventType.Layout)
            {
                var mousePosition = Event.current.mousePosition;
                var distance      = SpriteShapeHandleUtility.DistanceToArcWidth(mousePosition, rect.center, 0f, 360f, radius, AngleRangeGUI.kRangeWidth, angleOffset);

                HandleUtility.AddControl(m_CreateRangeControlID, distance);
            }
        }
Example #2
0
        public bool DoAngleRange(int index, Rect rect, float radius, float angleOffset, ref float start, ref float end, bool snap, bool disabled, Color gradientMin, Color gradientMid, Color gradientMax)
        {
            var changed = false;

            var controlID     = GUIUtility.GetControlID(kAngleRangeHashCode, FocusType.Passive);
            var leftHandleId  = GUIUtility.GetControlID(AngleRangeGUI.kLeftHandleHashCode, FocusType.Passive);
            var rightHandleId = GUIUtility.GetControlID(AngleRangeGUI.kRightHandleHashCode, FocusType.Passive);

            if (Event.current.type == EventType.Layout)
            {
                var distance = SpriteShapeHandleUtility.DistanceToArcWidth(Event.current.mousePosition, rect.center, start, end, radius, AngleRangeGUI.kRangeWidth, angleOffset);
                HandleUtility.AddControl(controlID, distance);

                if (HandleUtility.nearestControl == controlID)
                {
                    m_HoveredRangeIndex = index;
                    m_HoveredRangeID    = controlID;
                }
            }

            if (IsActionTriggering(AngleRangeAction.ModifyRange))
            {
                m_HotHandleID = m_HoveredHandleID;
                GrabKeyboardFocus(controlID);
            }

            if (m_RequestFocusIndex == index)
            {
                GrabKeyboardFocus(controlID);

                if (Event.current.type == EventType.Repaint)
                {
                    m_RequestFocusIndex = -1;
                }
            }

            using (new EditorGUI.DisabledScope(disabled))
            {
                var midAngle = (end - start) * 0.5f + start;
                var t        = 2f * (midAngle + 180f) / 360f;
                var color    = gradientMin;

                if (t < 1f)
                {
                    color = Color.Lerp(gradientMin, gradientMid, t);
                }
                else
                {
                    color = Color.Lerp(gradientMid, gradientMax, t - 1f);
                }

                if (!disabled)
                {
                    color = kNoKeboardFocusColor;

                    if (HasKeyboardFocus())
                    {
                        color = kHightlightColor;
                    }
                }

                EditorGUI.BeginChangeCheck();

                AngleRangeGUI.AngleRangeField(rect, leftHandleId, rightHandleId, ref start, ref end, angleOffset, radius, snap, false, false, color);

                changed = EditorGUI.EndChangeCheck();
            }

            //Extra Layout from handles
            if (Event.current.type == EventType.Layout &&
                (HandleUtility.nearestControl == leftHandleId ||  HandleUtility.nearestControl == rightHandleId))
            {
                m_HoveredRangeIndex = index;
                m_HoveredRangeID    = controlID;
                m_HoveredHandleID   = HandleUtility.nearestControl;
            }

            return(changed);
        }