コード例 #1
0
        private IEnumerator MoveToPos(int _newXpos, int _newYPos)
        {
            Vector2 oldPos   = RT.anchoredPosition;
            Vector2 newPos   = new Vector2(_newXpos, _newYPos);
            float   progress = 0.0f;
            float   speed    = VN.GetMovementSpeed();

            isMoving = true;
            switch (ScriptMaster.ActiveAnimationType)
            {
            case ScriptCompiler.ANIMATION_TYPES.SMOOTH:
                while (RT.anchoredPosition != newPos)
                {
                    if (isMoving == false)
                    {
                        break;
                    }
                    progress            = Mathf.Lerp(progress, 1.2f, Time.deltaTime * speed);
                    RT.anchoredPosition = Vector2.Lerp(oldPos, newPos, progress);
                    yield return(null);
                }
                break;

            case ScriptCompiler.ANIMATION_TYPES.LERP:
                while (RT.anchoredPosition != newPos)
                {
                    if (isMoving == false)
                    {
                        break;
                    }
                    progress           += Time.deltaTime * speed;
                    RT.anchoredPosition = Vector2.Lerp(oldPos, newPos, progress);
                    yield return(null);
                }
                break;
            }

            SM.FinishBackgroundMovement();
        }
コード例 #2
0
        private IEnumerator MoveToPos(int _newXpos, int _newYPos)
        {
            state = STATES.MOVING;
            Vector2 oldPos   = rect.anchoredPosition;
            Vector2 newPos   = new Vector2(_newXpos, _newYPos);
            float   progress = 0.0f;
            float   speed    = parent.GetMovementSpeed();

            switch (ScriptMaster.ActiveAnimationType)
            {
            case ScriptCompiler.ANIMATION_TYPES.SMOOTH:
                while (rect.anchoredPosition != newPos || progress <= 1.0f)
                {
                    //progress += Time.deltaTime * 1.0f;
                    progress = Mathf.Lerp(progress, 1.2f, Time.deltaTime * speed);
                    rect.anchoredPosition = Vector2.Lerp(oldPos, newPos, progress);
                    yield return(null);
                }
                break;

            case ScriptCompiler.ANIMATION_TYPES.LERP:
                while ((rect.anchoredPosition != newPos) || (progress < 1.0f))
                {
                    progress += Time.deltaTime * speed;
                    rect.anchoredPosition = Vector2.Lerp(oldPos, newPos, progress);
                    yield return(null);
                }
                break;
            }

            rect.anchoredPosition = newPos;
            if (state == STATES.MOVING)
            {
                state = STATES.IDLE;
            }
            //SM.FinishBackgroundMovement();
        }