Esempio n. 1
0
        private void SimpleMoveAlongPath(float delay, EaseAnim easeAnim, Action completeCallBack)
        {
            if (path == null || path.Count == 0)
            {
                //   Debug.Log("move start return");
                if (completeCallBack != null)
                {
                    completeCallBack();
                }
                return;
            }

            //  Debug.Log("move start");
            pathPoints    = new Vector2[path.Count + 1];
            pathPoints[0] = transform.localPosition;
            for (int i = 1; i < pathPoints.Length; i++)
            {
                pathPoints[i] = path[i - 1].gCell.transform.localPosition;
            }

            moving = true;
            PolyLine plPath    = new PolyLine(pathPoints);
            float    time      = plPath.Length / speed;
            int      segNumber = 0;

            tweenID = SimpleTween.Value(gameObject, 0, plPath.Length, time).
                      SetOnUpdate((float d) =>
            {
                if (this)
                {
                    gameObject.transform.localPosition = plPath.GetPolyLinePosition(d, out segNumber);
                    if (path != null && segNumber < path.Count)
                    {
                        anchored = path[segNumber].gCell;
                    }
                }
            }).SetEase(easeAnim).SetDelay(delay).
                      AddCompleteCallBack(() =>
            {
                // Debug.Log("tween complete callback");
                moving = false;
                if (completeCallBack != null)
                {
                    completeCallBack();
                }
            }).ID;
        }