Example #1
0
        public Vector2 Update(Vector2 touchPosition, float deltaTime)
        {
            var delta = Vector2.zero;

            switch (State)
            {
            case ScrollerState.Idle:
                break;

            case ScrollerState.Scrolling:
                delta = touchPosition - _lastTouchPosition;
                RecordSpeed(delta / deltaTime);
                _lastTouchPosition = touchPosition;

                break;

            case ScrollerState.Decelerating:
                delta  = GetDeceleratingSpeed(deltaTime) * deltaTime;
                _speed = delta / deltaTime;

                if (Mathf.Approximately(_speed.sqrMagnitude, 0f))
                {
                    State = ScrollerState.Idle;
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(delta);
        }
Example #2
0
 public void DoTouch(Vector2 touchPosition)
 {
     _touchSpeedQueue.Clear();
     State              = ScrollerState.Scrolling;
     _speed             = Vector2.zero;
     _lastTouchPosition = touchPosition;
 }
Example #3
0
 public void ZeroSpeed()
 {
     _speed = Vector2.zero;
     State  = ScrollerState.Idle;
 }
Example #4
0
 public void DoUntouch()
 {
     State  = ScrollerState.Decelerating;
     _speed = GetReleaseSpeed();
     _speed = Vector2.ClampMagnitude(_speed, _maxReleaseSpeed);
 }
 public void StopScroller()
 {
     currentScrollerState = ScrollerState.Stopped;
 }
 public void StartScroller()
 {
     currentScrollerState = ScrollerState.Moving;
 }