Exemple #1
0
 public void DrawAngleRangeOutline(Rect rect, float start, float end, float angleOffset, float radius)
 {
     if (Event.current.type == EventType.Repaint)
     {
         SpriteShapeHandleUtility.DrawRangeOutline(start, end, angleOffset, rect.center, radius, AngleRangeGUI.kRangeWidth - 1f);
     }
 }
Exemple #2
0
        public void CycleSpriteIndex()
        {
            ISelection selection = ShapeEditorCache.GetSelection();

            if (selection.single == -1)
            {
                return;
            }

            int   nextIndex       = SplineUtility.NextIndex(selection.single, m_Spline.GetPointCount());
            float angle           = SpriteShapeHandleUtility.PosToAngle(m_Spline.GetPosition(selection.single), m_Spline.GetPosition(nextIndex), 0f);
            int   angleRangeIndex = SpriteShapeEditorUtility.GetRangeIndexFromAngle(m_SpriteShape, angle);

            if (angleRangeIndex == -1)
            {
                return;
            }

            AngleRange angleRange = m_SpriteShape.angleRanges[angleRangeIndex];

            int spriteIndex = (m_Spline.GetSpriteIndex(selection.single) + 1) % angleRange.sprites.Count;

            Undo.RecordObject(m_CurrentEditor.target, "Edit Sprite Index");

            m_Spline.SetSpriteIndex(selection.single, spriteIndex);

            EditorUtility.SetDirty(m_CurrentEditor.target);
        }
Exemple #3
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);
            }
        }
        private void DoRangesGUI()
        {
            var radius = controller.radius;

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            var rect = EditorGUILayout.GetControlRect(false, radius * 2f);

            if (Event.current.type == EventType.Repaint)
            {
                m_AngleRangeRect = rect;
            }

            {   //Draw background
                var backgroundColor      = Contents.proBackgroundColor;
                var backgroundRangeColor = Contents.proBackgroundRangeColor;

                if (!EditorGUIUtility.isProSkin)
                {
                    backgroundColor        = Contents.defaultBackgroundColor;
                    backgroundRangeColor.a = 0.1f;
                }
                var c = Handles.color;
                Handles.color = backgroundRangeColor;
                SpriteShapeHandleUtility.DrawSolidArc(rect.center, Vector3.forward, Vector3.right, 360f, radius, AngleRangeGUI.kRangeWidth);
                Handles.color = backgroundColor;
                Handles.DrawSolidDisc(rect.center, Vector3.forward, radius - AngleRangeGUI.kRangeWidth + 1f);
                Handles.color = c;
            }

            if (targets.Length == 1)
            {
                {   //Draw fill texture and sprite preview
                    SpriteShapeHandleUtility.DrawTextureArc(
                        m_FillTextureProp.objectReferenceValue as Texture, 100.0f,
                        rect.center, Vector3.forward, Quaternion.AngleAxis(m_PreviewAngle, Vector3.forward) * Vector3.right, 180f,
                        radius - AngleRangeGUI.kRangeWidth);

                    var rectSize = Vector2.one * (radius - AngleRangeGUI.kRangeWidth) * 2f;
                    rectSize.y *= 0.33f;
                    var spriteRect = new Rect(rect.center - rectSize * 0.5f, rectSize);
                    DrawSpritePreview(spriteRect);
                    HandleSpritePreviewCycle(spriteRect);
                }

                controller.rect = m_AngleRangeRect;
                controller.OnGUI();
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }
Exemple #5
0
        public static float AngleField(Rect rect, int id, float angle, float angleOffset, Vector2 handleOffset, float handleAngle, float handleSize, float radius, bool snap, bool drawLine, bool drawCircle, Handles.CapFunction drawCapFunction)
        {
            float   offsetedAngle = angle + angleOffset;
            Vector2 pos           = new Vector2(Mathf.Cos(offsetedAngle * Mathf.Deg2Rad), Mathf.Sin(offsetedAngle * Mathf.Deg2Rad)) * radius + rect.center;

            if (Event.current.type == EventType.Repaint)
            {
                if (drawCircle)
                {
                    Handles.DrawWireDisc(rect.center, Vector3.forward, radius);
                }

                if (drawLine)
                {
                    Handles.DrawLine(rect.center, pos);
                }
            }

            if (GUI.enabled)
            {
                EditorGUI.BeginChangeCheck();

                Quaternion rotation = Quaternion.AngleAxis(handleAngle, Vector3.forward);
                Vector2    posNew   = SpriteShapeHandleUtility.Slider2D(id, pos, rotation * handleOffset, rotation, handleSize, drawCapFunction);

                if (EditorGUI.EndChangeCheck())
                {
                    Vector2 v1 = pos - rect.center;
                    Vector2 v2 = posNew - rect.center;

                    float angleDirection = Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(v1, v2)));
                    float angleIncrement = Vector2.Angle(v1, v2);

                    angle += angleIncrement * angleDirection;

                    if (snap)
                    {
                        angle = Mathf.RoundToInt(angle);
                    }
                }
            }

            return(angle);
        }
Exemple #6
0
        public static void AngleRangeField(Rect rect, int leftHandleID, int rightHandleID, ref float start, ref float end, float angleOffset, float radius, bool snap, bool drawLine, bool drawCircle, Color rangeColor)
        {
            Color activeColor = Handles.color;

            if (Event.current.type == EventType.Repaint)
            {
                float range = end - start;

                Color color = Handles.color;
                Handles.color = rangeColor;
                if (range < 0f)
                {
                    Handles.color = Color.red;
                }

                SpriteShapeHandleUtility.DrawSolidArc(rect.center, Vector3.forward, Quaternion.AngleAxis(start + angleOffset, Vector3.forward) * Vector3.right, range, radius, kRangeWidth);
                Handles.color = color;
            }

            EditorGUI.BeginChangeCheck();

            float handleSize = 15f;

            start = AngleField(rect, leftHandleID, start, angleOffset, new Vector2(-3.5f, -7.5f), start + angleOffset + 90f, handleSize, radius, snap, drawLine, drawCircle, SpriteShapeHandleUtility.RangeLeftCap);

            if (EditorGUI.EndChangeCheck())
            {
                start = Mathf.Clamp(start, end - 360f, end);
            }

            EditorGUI.BeginChangeCheck();

            end = AngleField(rect, rightHandleID, end, angleOffset, new Vector2(3.5f, -7.5f), end + angleOffset + 90f, handleSize, radius, snap, drawLine, false, SpriteShapeHandleUtility.RangeRightCap);

            if (EditorGUI.EndChangeCheck())
            {
                end = Mathf.Clamp(end, end, start + 360f);
            }

            Handles.color = activeColor;
        }
Exemple #7
0
 public float GetAngleFromPosition(Rect rect, float angleOffset)
 {
     return(Mathf.RoundToInt(SpriteShapeHandleUtility.PosToAngle(Event.current.mousePosition, rect.center, -angleOffset)));
 }
Exemple #8
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);
        }