Esempio n. 1
0
    public void OnDrawGizmos()
    {
        // This actually calculates 1000 points along the bezier curve each time the gizmos update.
        // It seems like this would kill unity but the calculations are suprisingly fast and it doesn't
        // seem to cause a problem. It might be an issue if you have lots of these but you can turn them
        // off using DrawGizmos.
        if (this.DrawGizmos)
        {
            List <BezierWaypoint> gizmoWaypointList = new List <BezierWaypoint>();

            foreach (BezierWaypoint comp in gameObject.GetComponentsInChildren(typeof(BezierWaypoint)))
            {
                comp.SetControlPoints();
                if (comp.IsValid)
                {
                    gizmoWaypointList.Add(comp);
                }
            }

            if (gizmoWaypointList.Count != 0)
            {
                MyBezier gizmoBezier = new MyBezier(gizmoWaypointList.ToArray());

                for (float t = 0.0f; t < 1.0f; t += 0.001f)
                {
                    Gizmos.DrawIcon(gizmoBezier.GetPointAtTime(t, this.IsFullLoop), "/Bezier/BezierCurve.png");
                }
            }
        }
    }
Esempio n. 2
0
    public void Init(GameObject posTarget, Model_Building model_building)
    {
        _posTarget      = posTarget;
        _model_Building = model_building;

        float randX = UnityEngine.Random.Range(-0.8f, 0.8f);
        float randY = UnityEngine.Random.Range(0.5f, 1f);

        Vector3 contr1 = new Vector3(randX, randY, 0f);

        _rotation.to = new Vector3(0f, UnityEngine.Random.Range(90f, 360f), 0f);
        _rotation.Play();
//		Vector3 pos = transform.InverseTransformPoint(_posTarget.transform.position);
//		Trace.trace(" pos x = " + pos.x + " y = " + pos.y + "_posTarget  x = " + _posTarget.transform.position.x + " y  = " + _posTarget.transform.position.y, Trace.CHANNEL.UI);
        MyBezier bezier = new MyBezier(this.transform.position, contr1, new Vector3(1f, -1f, 0f), _posTarget.transform.position);

        int pointSize = 180 + UnityEngine.Random.Range(0, 50);

        resultList = new Vector3[pointSize];
        for (int index = 1; index <= pointSize; index++)
        {
            resultList[index - 1] = bezier.GetPointAtTime((float)index / (float)pointSize);
        }
        length = resultList.Length;
        // 随机
        float randDelay = UnityEngine.Random.Range(0.1f, 1.3f);

        StartCoroutine(Move(randDelay));
    }
Esempio n. 3
0
        private List <MyShape> parseStringDataToListShapeObject(string data)
        {
            List <MyShape> myShapes  = new List <MyShape>();
            string         firstWord = null;

            string[] listShape = data.Split('\n');
            for (int i = 0; i < listShape.Length; i++)
            {
                if (listShape[i] != "")
                {
                    firstWord = listShape[i].Substring(0, listShape[i].IndexOf(" "));
                }
                switch (firstWord)
                {
                case "Line":
                    MyShape myLine = new MyLine();
                    myLine.Open(listShape[i]);
                    myShapes.Add(myLine);
                    break;

                case "Rectangle":
                    MyShape myRectangle = new MyRectangle();
                    myRectangle.Open(listShape[i]);
                    myShapes.Add(myRectangle);
                    break;

                case "Circle":
                    MyShape myCircle = new MyCircle();
                    myCircle.Open(listShape[i]);
                    myShapes.Add(myCircle);
                    break;

                case "Ellipse":
                    MyShape myEllipse = new MyEllipse();
                    myEllipse.Open(listShape[i]);
                    myShapes.Add(myEllipse);
                    break;

                case "Polygon":
                    MyShape myPolygon = new MyPolygon();
                    myPolygon.Open(listShape[i]);
                    myShapes.Add(myPolygon);
                    break;

                case "Bezier":
                    MyShape myBezier = new MyBezier();
                    myBezier.Open(listShape[i]);
                    myShapes.Add(myBezier);
                    break;

                case "Polyline":
                    MyShape myPolyline = new MyPolyline();
                    myPolyline.Open(listShape[i]);
                    myShapes.Add(myPolyline);
                    break;
                }
                firstWord = "";
            }
            return(myShapes);
        }
Esempio n. 4
0
 void Awake()
 {
     foreach (IBezierWaypoint comp in gameObject.GetComponentsInChildren(typeof(IBezierWaypoint)))
     {
         this.waypointList.Add(comp);
     }
     this.bezier = new MyBezier(this.waypointList.ToArray());
 }
Esempio n. 5
0
        //画贝塞尔曲线
        private void AddBezier(Point pt1, Point pt2, Point pt3, Point pt0)
        {
            MyBezier mb = new MyBezier(pt1, pt2, pt3, pt0);

            mb.drawmode = new GeometryMode(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), pen);
            compositeGraphic.Add(mb);
            du_refresh();
            canvas1.ReleaseMouseCapture();
        }