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); }
public void DoTouch(Vector2 touchPosition) { _touchSpeedQueue.Clear(); State = ScrollerState.Scrolling; _speed = Vector2.zero; _lastTouchPosition = touchPosition; }
public void ZeroSpeed() { _speed = Vector2.zero; State = ScrollerState.Idle; }
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; }