Exemple #1
0
    public float GetDistance(float deltaTime)
    {
        var distance = 0.0f;

        if (_isDragging)
        {
            _isDragging = false;
            distance    = _draggingDistance;

            if (IsGoingTooFar(_draggingDistance))
            {
                var threshold = _overGoingDistanceThreshold * Mathf.Sign(_overGoingDistance);
                distance -= _overGoingDistance - threshold;
            }
        }
        else if (!_aligningMovement.IsMovementEnded())
        {
            distance = _aligningMovement.GetDistance(deltaTime);
        }
        else if (!_releasingMovement.IsMovementEnded())
        {
            distance = _releasingMovement.GetDistance(deltaTime);

            if (NeedToAlign(distance))
            {
                _releasingMovement.EndMovement();

                _aligningMovement.SetMovement(_getAligningDistance());
                distance = _aligningMovement.GetDistance(deltaTime);
            }
        }

        return(distance);
    }
Exemple #2
0
    /* Get moving distance in the given delta time
     */
    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(_draggingDistance))
            {
                var threshold = _overGoingDistanceThreshold * Mathf.Sign(_overGoingDistance);
                distance -= _overGoingDistance - threshold;
            }
        }
        /* Aligning */
        else if (!_aligningMovement.IsMovementEnded())
        {
            distance = _aligningMovement.GetDistance(deltaTime);
        }
        /* Releasing */
        else if (!_releasingMovement.IsMovementEnded())
        {
            distance = _releasingMovement.GetDistance(deltaTime);

            if (NeedToAlign(distance))
            {
                // Make the releasing movement end
                _releasingMovement.EndMovement();

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

        return(distance);
    }