Example #1
0
    public static Path CreateAppearPath(Vector3 startingPosition, Vector3 formationPosition, int loopsCount = 0)
    {
        Path appearPath = new Path();

        float screenSideSign = Mathf.Sign(startingPosition.x);

        appearPath.AddCurve(new BezierCurve(startingPosition, startingPosition, new Vector2(screenSideSign * 3, 2), new Vector2(screenSideSign * 2, 0), 30));
        appearPath.AddCurve(new BezierCurve(new Vector2(screenSideSign * 2, 0), new Vector2(screenSideSign * 1, -3), new Vector2(screenSideSign * 5, -1f), new Vector2(screenSideSign * 3, 0), 30));

        for (int i = 0; i < loopsCount; i++)
        {
            appearPath.AddCurve(new BezierCurve(new Vector2(screenSideSign * 3, 0), new Vector2(screenSideSign * 2, .5f), new Vector2(screenSideSign * 1, -1.5f), new Vector2(screenSideSign * 3, -1.5f), 30));
            appearPath.AddCurve(new BezierCurve(new Vector2(screenSideSign * 3, -1.5f), new Vector2(screenSideSign * 3.5f, -1.5f), new Vector2(screenSideSign * 4f, -0.3f), new Vector2(screenSideSign * 3, 0), 30));
        }

        appearPath.AddCurve(new BezierCurve(new Vector2(screenSideSign * 3, 0), new Vector2(screenSideSign * 2, .5f), formationPosition + Vector3.up * 2f, formationPosition, 30));

        return(appearPath);
    }
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (GUILayout.Button("Add Curve"))
        {
            Undo.RecordObject(_path, "Add Curve");
            _path.AddCurve();
            EditorUtility.SetDirty(_path);
        }
    }
Example #3
0
    public static Path CreateDiveInPath(Vector3 startingPosition, float amplitude = 0.5f)
    {
        amplitude *= Mathf.Sign(startingPosition.x);

        Path  diveInPath     = new Path();
        float screenSideSign = Mathf.Sign(startingPosition.x);

        (Vector2 startPoint, Vector2 controlPoint)curveStartPoints = (startingPosition, startingPosition);
        (Vector2 endPoint, Vector2 controlPoint)curveEndPoints     = (new Vector2(startingPosition.x + amplitude, startingPosition.y - 1), new Vector2(startingPosition.x, startingPosition.y - 1));
        diveInPath.AddCurve(curveStartPoints, curveEndPoints, 30);

        for (int i = 0; i < 10; i++)
        {
            float sign = Mathf.Pow(-1, i);
            curveStartPoints = (new Vector2(startingPosition.x + sign * amplitude, startingPosition.y - (i + 1)), new Vector2(startingPosition.x + sign * amplitude * 3, startingPosition.y - (i + 1.2f)));
            curveEndPoints   = (new Vector2(startingPosition.x - sign * amplitude, startingPosition.y - (i + 2)), new Vector2(startingPosition.x, startingPosition.y - (i + 2)));
            diveInPath.AddCurve(curveStartPoints, curveEndPoints, 30);
        }


        return(diveInPath);
    }
        /// <summary>
        /// Creates the GraphicsPath for the balloon
        /// </summary>
        /// <remarks></remarks>
        private void RecreatePath()
        {
            //'NOTE: To make creating the path easier, I assume the origin is (0, 0)
            //'when adding the points to the GraphicsPath. When it comes time to
            //'actually draw the balloon, I'll call TranslateTransform on the
            //'Graphics object to shift the origin to the actual location as
            //'determined in the Bounds property.

            //Empty the path:
            Path.Reset();

            //If the BubbleSize is 0, we'll just create an ellipse:
            switch (Shape)
            {
            case (BalloonShape.Rectangle):
            {
                if (RectangleCornerRadius == 0)
                {
                    //Do the easy one:
                    Path.AddRectangle(new Rectangle(0, 0, Width, Height));
                }
                else
                {
                    //Round Rectangle code adapter from http://www.bobpowell.net/roundrects.htm
                    Path.AddLine(0 + RectangleCornerRadius, 0, 0 + Width - (RectangleCornerRadius * 2), 0);
                    Path.AddArc(0 + Width - (RectangleCornerRadius * 2), 0, RectangleCornerRadius * 2, RectangleCornerRadius * 2, 270, 90);
                    Path.AddLine(0 + Width, 0 + RectangleCornerRadius, 0 + Width, 0 + Height - (RectangleCornerRadius * 2));
                    Path.AddArc(0 + Width - (RectangleCornerRadius * 2), 0 + Height - (RectangleCornerRadius * 2), RectangleCornerRadius * 2, RectangleCornerRadius * 2, 0, 90);
                    Path.AddLine(0 + Width - (RectangleCornerRadius * 2), 0 + Height, 0 + RectangleCornerRadius, 0 + Height);
                    Path.AddArc(0, 0 + Height - (RectangleCornerRadius * 2), RectangleCornerRadius * 2, RectangleCornerRadius * 2, 90, 90);
                    Path.AddLine(0, 0 + Height - (RectangleCornerRadius * 2), 0, 0 + RectangleCornerRadius);
                    Path.AddArc(0, 0, RectangleCornerRadius * 2, RectangleCornerRadius * 2, 180, 90);
                }
                break;
            }

            case (BalloonShape.Ellipse):
            {
                if (BubbleSize == 0)
                {
                    Path.AddEllipse(0, 0, Width, Height);
                }
                else
                {
                    int theta = 0;

                    //Do an angle sweep around the circle moving the BubbleWidth in each iteration:
                    for (theta = 0; theta <= (360 - BubbleWidth); theta += BubbleWidth)
                    {
                        var points = new Point[2];

                        double radianTheta  = theta * Math.PI / 180;
                        double radianTheta2 = (theta + (BubbleWidth / 2)) * Math.PI / 180;
                        double radianTheta3 = (theta + BubbleWidth) * Math.PI / 180;

                        var x = (int)((Width / 2) + (Width / 2) * Math.Cos(radianTheta));
                        var y = (int)((Height / 2) + (Height / 2) * Math.Sin(radianTheta));

                        int xdelta = 0;
                        int ydelta = 0;

                        if (Math.Cos(radianTheta2) < 0 && Math.Sin(radianTheta2) < 0)
                        {
                            //'Top-left:
                            xdelta = -BubbleSize;
                            ydelta = -BubbleSize;
                        }
                        else if (Math.Cos(radianTheta2) > 0 && Math.Sin(radianTheta2) > 0)
                        {
                            //Bottom-Right, Good
                            xdelta = BubbleSize;
                            ydelta = BubbleSize;
                        }
                        else if (Math.Cos(radianTheta2) < 0 && Math.Sin(radianTheta2) > 0)
                        {
                            //Bottom-Left, Good
                            xdelta = -BubbleSize;
                            ydelta = BubbleSize;
                        }
                        else if (Math.Cos(radianTheta2) > 0 && Math.Sin(radianTheta2) < 0)
                        {
                            //Top-Right
                            xdelta = BubbleSize;
                            ydelta = -BubbleSize;
                        }

                        var x2 = (int)(((Width / 2) + (Width / 2) * Math.Cos(radianTheta2)) + xdelta);
                        var y2 = (int)(((Height / 2) + (Height / 2) * Math.Sin(radianTheta2)) + ydelta);

                        var x3 = (int)((Width / 2) + (Width / 2) * Math.Cos(radianTheta3));
                        var y3 = (int)((Height / 2) + (Height / 2) * Math.Sin(radianTheta3));

                        //Build the triangle between the start angle, the point away from the balloon
                        //(as determined by the BubbleSize), and the sweep angle:

                        points[0] = new Point(x, y);
                        points[1] = new Point(x2, y2);
                        points[2] = new Point(x3, y3);

                        //The BubbleSmoothness value determines how curve-like the lines
                        //between the three points will be:
                        Path.AddCurve(points, BubbleSmoothness);
                    }
                }
                break;
            }
            }

            //Finish off the path:
            Path.CloseAllFigures();
        }