コード例 #1
0
        public static Vector2 GetPointOnConnection(float t, Vector2 start, Vector2 end, Edge startEdge, Edge?endEdge, float relativeBend = 1 / 4f, float minBend = 0)
        {
            var startTangent = GetStartTangent(start, end, startEdge, endEdge, relativeBend, minBend);
            var endTangent   = GetEndTangent(start, end, startEdge, endEdge, relativeBend, minBend);

            return(MathfEx.Bezier(start, end, startTangent, endTangent, t));
        }
コード例 #2
0
        public static void DrawGrid(Vector2 scroll, Rect position, float zoom = 1)
        {
            if (e.type != EventType.Repaint)
            {
                return;
            }

            var i = 0;

            var drawMinor = zoom >= 0.75f;

            var width = MathfEx.HigherMultiple(position.width, Styles.minorGridSpacing * Styles.majorGridGroup);

            for (var x = position.x; x < position.x + width; x += Styles.minorGridSpacing)
            {
                var xWrap = MathfEx.Wrap(x - scroll.x, width);

                if (i == 0)
                {
                    EditorGUI.DrawRect(new Rect
                                       (
                                           xWrap,
                                           0,
                                           Styles.majorGridThickness / zoom,
                                           position.height
                                       ), Styles.majorGridColor);
                }
                else if (drawMinor)
                {
                    EditorGUI.DrawRect(new Rect
                                       (
                                           xWrap,
                                           0,
                                           Styles.minorGridThickness / zoom,
                                           position.height
                                       ), Styles.minorGridColor);
                }

                i = (i + 1) % Styles.majorGridGroup;
            }

            var j = 0;

            var height = MathfEx.HigherMultiple(position.height, Styles.minorGridSpacing * Styles.majorGridGroup);

            for (var y = position.y; y < position.y + height; y += Styles.minorGridSpacing)
            {
                var yWrap = MathfEx.Wrap(y - scroll.y, height);

                if (j == 0)
                {
                    EditorGUI.DrawRect(new Rect
                                       (
                                           0,
                                           yWrap,
                                           position.width,
                                           Styles.majorGridThickness / zoom
                                       ), Styles.majorGridColor);
                }
                else if (drawMinor)
                {
                    EditorGUI.DrawRect(new Rect
                                       (
                                           0,
                                           yWrap,
                                           position.width,
                                           Styles.minorGridThickness / zoom
                                       ), Styles.minorGridColor);
                }

                j = (j + 1) % Styles.majorGridGroup;
            }

            if (LudiqCore.Configuration.developerMode && LudiqGraphs.Configuration.debug)
            {
                GUI.Label(new Rect(position.position, new Vector2(500, 16)), "Scroll: " + scroll, EditorStyles.whiteLabel);
                GUI.Label(new Rect(position.position + new Vector2(0, 16), new Vector2(500, 16)), "Position: " + position, EditorStyles.whiteLabel);
                GUI.Label(new Rect(position.position + new Vector2(0, 32), new Vector2(500, 16)), "Hot Controls: " + GUIUtility.hotControl + " / " + GUIUtility.keyboardControl, EditorStyles.whiteLabel);
            }
        }
コード例 #3
0
 public static float SnapToGrid(float position)
 {
     return(MathfEx.NearestMultiple(position, Styles.minorGridSpacing));
 }