Example #1
0
        /// <summary>
        /// Get the moving distance for the next delta time
        /// </summary>
        public float GetDistance(float deltaTime)
        {
            var distance = 0.0f;

            /* If it's dragging, return the dragging distance set from `SetMovement()` */
            if (_isDragging)
            {
                _isDragging = false;
                distance    = _draggingDistance;

                if (!IsGoingTooFar(distance))
                {
                    return(distance);
                }

                var exceedingDistance = _getAligningDistance() * -1;
                var limit             =
                    _exceedingDistanceLimit * Mathf.Sign(exceedingDistance);
                distance = limit - exceedingDistance;
            }
            /* Aligning */
            else if (!_aligningMovementCurve.IsMovementEnded())
            {
                distance = _aligningMovementCurve.GetDistance(deltaTime);
            }
            /* Releasing */
            else if (!_releasingMovementCurve.IsMovementEnded())
            {
                distance = _releasingMovementCurve.GetDistance(deltaTime);

                if (!IsGoingTooFar(distance) && !IsTooSlow())
                {
                    return(distance);
                }

                // Make the releasing movement end
                _releasingMovementCurve.EndMovement();

                // Start the aligning movement instead
                _aligningMovementCurve.SetMovement(_getAligningDistance());
                distance = _aligningMovementCurve.GetDistance(deltaTime);
            }

            return(distance);
        }
        /// <summary>
        /// Get the moving distance for the next delta time
        /// </summary>
        /// <param name="deltaTime">The next delta time</param>
        /// <returns>The moving distance in this period</returns>
        public float GetDistance(float deltaTime)
        {
            if (!_bouncingMovementCurve.IsMovementEnded())
            {
                return(_bouncingMovementCurve.GetDistance(deltaTime));
            }

            var distance = _unitMovementCurve.GetDistance(deltaTime);

            if (!NeedToBounceBack(distance))
            {
                return(distance);
            }

            // Make the unit movement end
            _unitMovementCurve.EndMovement();

            _bouncingMovementCurve.SetMovement(-1 * _getAligningDistance());
            // Start at the furthest point to move back
            _bouncingMovementCurve.GetDistance(0.125f);
            return(_bouncingMovementCurve.GetDistance(deltaTime));
        }