Exemplo n.º 1
0
        void RunTo(Vector3 startPos, Vector3 endPos, float delayTime, float showTime, TrailConfig config)
        {
            StartCoroutine(CurveAction(startPos, endPos, Vector3.up, delayTime, showTime));
            Destroy(gameObject, delayTime + showTime);
            return;             //----------------------curve---------------

            int   minAngle = config.MinAngle;
            int   maxAngle = config.MaxAngle;
            float minDist  = config.MinDistRatio;
            float maxDist  = config.MaxDistRatio;

            int angle = UnityEngine.Random.Range(minAngle, maxAngle);

            if (MTRandom.GetRandomInt(1, 2) > 1)
            {
                angle = -angle;
            }

            Vector3 dis = new Vector3(endPos.x - startPos.x, endPos.y - startPos.y, 0);
            float   r   = Mathf.Atan2(dis.y, dis.x) * 180 / Mathf.PI;

            angle += (int)r;

            //计算两点之间随机值
            float   dist      = UnityEngine.Random.Range(minDist, maxDist);
            Vector3 middlePos = Vector3.Lerp(startPos, endPos, dist);

            dist = Vector3.Distance(startPos, middlePos);

//		middlePos = Vector3.RotateTowards

            float distx = Mathf.Cos(angle) * dist;
            float disty = Mathf.Sin(angle) * dist;

            Vector3 c1 = new Vector3(distx + startPos.x, disty + startPos.y, 0);

//		c1 = new Vector3 (c1.x / 100, c1.y / 100, 0);
//		endPos = new Vector3 (endPos.x / 100, endPos.y / 100, 0);

            MTBezierConfig bconfig = new MTBezierConfig();

            bconfig.ControlPoint1 = c1;
            bconfig.ControlPoint2 = c1;
            bconfig.EndPosition   = endPos;

            MTBezierTo action = new MTBezierTo(showTime, bconfig);

//		trail.gameObject.RunAction (action);
            trail.gameObject.RunActions(new MTDelayTime(delayTime), action, new MTDestroy());



//		MTMoveTo action = new MTMoveTo (showTime, endPos);
//		trail.gameObject.RunAction (action);
        }
Exemplo n.º 2
0
        public static void CreateRender(Transform parent, Vector3 startPos, Vector3 endPos, float delayTime, float showTime, TrailConfig config, GameObject go)
        {
            go.transform.localPosition = startPos;
            TransformUtil.AddChild(parent, go.transform);
            Trail trail = go.GetComponent <Trail> ();

            if (trail == null)
            {
                trail = go.AddComponent <Trail> ();
            }
            trail.RunTo(startPos, endPos, delayTime, showTime, config);
        }