// Update is called once per frame
        void Update()
        {
            if (phase == SlidingPhase.MovingIn)
            {
                transform.position = Vector3.Lerp(startPosition, targetPosition, (Time.time - startTime) / elapseTime);
                //// transform.position = targetPosition;

                if (transform.position == targetPosition)
                {
                    phase = SlidingPhase.Idle;
                }
            }
            else if (phase == SlidingPhase.MovingOut)
            {
                transform.position = Vector3.Lerp(targetPosition, startPosition, (Time.time - startTime) / elapseTime);

                if (transform.position == startPosition)
                {
                    if (closingCallback != null)
                    {
                        closingCallback();
                    }
                }
            }
        }
        // Start is called before the first frame update
        void Start()
        {
            targetPosition = this.transform.position;
            switch (direction)
            {
            case SlidingDirection.Left:
                startPosition = new Vector3(targetPosition.x - 5, targetPosition.y, targetPosition.z);
                break;

            case SlidingDirection.Right:
                startPosition = new Vector3(targetPosition.x + 12, targetPosition.y, targetPosition.z);
                break;

            case SlidingDirection.Down:
                startPosition = new Vector3(targetPosition.x, targetPosition.y - 10, targetPosition.z);
                break;

            default:
                break;
            }

            this.transform.position = startPosition;

            startTime = Time.time;
            phase     = SlidingPhase.MovingIn;
        }
示例#3
0
        void Update()
        {
            switch (phase)
            {
            case SlidingPhase.Closed:                     // go to sleep
                enabled = false;
                t       = 0;
                break;

            case SlidingPhase.Opening:
                t += speed * Time.deltaTime;
                if (t >= 1)
                {
                    t     = 1;
                    phase = SlidingPhase.Opened;
                }

                transform.localPosition = Vector2.Lerp(
                    closePosition, openPosition, t);
                break;

            case SlidingPhase.Opened:
                // nothing to do?
                break;

            case SlidingPhase.Closing:
                t -= speed * Time.deltaTime;
                if (t <= 0)
                {
                    t     = 0;
                    phase = SlidingPhase.Closed;
                }

                transform.localPosition = Vector2.Lerp(
                    closePosition, openPosition, t);
                break;
            }
        }
示例#4
0
 // Start is called before the first frame update
 void Start()
 {
     startTime = Time.time;
     phase     = SlidingPhase.MovingIn;
 }
示例#5
0
 public void Close(Action callback = null)
 {
     startTime            = Time.time;
     phase                = SlidingPhase.MovingOut;
     this.closingCallback = callback;
 }
示例#6
0
 public void Close()
 {
     phase = SlidingPhase.Closing;
 }
示例#7
0
 public void Open()
 {
     enabled = true;
     phase   = SlidingPhase.Opening;
 }