Esempio n. 1
0
        /// <summary>
        /// Updates the slider's fill amount, handle position and sets the output value.
        /// </summary>
        private void UpdateSlider()
        {
            var padXCurrentFrame = ControllerManager.Instance.GetTouchpadAxis().x;

            // Delta of the touchpad x-values.
            var padXDelta = padXCurrentFrame - _padXLastFrame;

            // Increment how much the touchpad has been slid.
            _incrementedMoveAmount += padXDelta * MultiplierToMatchTouchpadMovement * _touchPadMultiplier;

            // Don't update the slider if the user is trying to slide outside of the scope.
            if (TryingToSlideOutsideOfScope())
            {
                _incrementedMoveAmount = 0;
                _padXLastFrame         = padXCurrentFrame;
                return;
            }

            // Calculate the size per step.
            _sizePerStep = 1f / (_maxValue - _minValue);

            // If the incremented slide amount is bigger than a step on discrete slider, update the slider value.
            if (Mathf.Abs(_incrementedMoveAmount) > _sizePerStep)
            {
                // Determine the number of steps to move.
                _stepsToMove = (int)(_incrementedMoveAmount / _sizePerStep);

                // Reset the value after it has been used to update the current step.
                _incrementedMoveAmount = 0;

                // Updates the current step.
                _currentStep = Mathf.Clamp(_currentStep + _stepsToMove, 0, _maxValue - _minValue);
                _stepsToMove = 0;

                ControllerManager.Instance.TriggerHapticPulse(_hapticStrength);
            }

            // Update the variable holding how much the slider should be filled and set the graphical fill amount.
            _sliderFillAmount = _currentStep * _sizePerStep;
            _sliderGraphics.SetFillAmount(_sliderFillAmount);

            // Calculate the new value and update the value text.
            Value = (int)Mathf.Lerp(_minValue, _maxValue, _sliderFillAmount);
            _sliderGraphics.UpdateValueText(Value);

            _padXLastFrame = padXCurrentFrame;
        }
    /// <summary>
    /// Updates the slider's fill amount, handle position and sets the output value.
    /// </summary>
    private void UpdateSlider()
    {
        // Increment how much the touchpad has been dragged.
        _incrementedMoveAmount += GetRelativeControllerMovement().x *_controllerMovementMultiplier;

        // Resets the incremented delta for the discrete slider if dragging outside of the slider's scope (above max or below min).
        if (TryingToDragOutsideOfScope())
        {
            _incrementedMoveAmount = 0;
            return;
        }

        // Calculate the size per step.
        _sizePerStep = 1f / (_maxValue - _minValue);

        // If the incremented drag amount is bigger than a step on discrete slider, update the slider value.
        if (Mathf.Abs(_incrementedMoveAmount) > _sizePerStep)
        {
            // Determine the number of steps to move.
            _stepsToMove = (int)(_incrementedMoveAmount / _sizePerStep);

            // Reset the value after it has been used to update the current step.
            _incrementedMoveAmount = 0;

            // Updates the current step.
            _currentStep = Mathf.Clamp(_currentStep + _stepsToMove, 0, _maxValue - _minValue);
            _stepsToMove = 0;

            ControllerManager.Instance.TriggerHapticPulse(_hapticStrength);
        }

        // Update the variable holding how much the slider should be filled and set the graphical fill amount.
        _sliderFillAmount = _currentStep * _sizePerStep;
        _sliderGraphics.SetFillAmount(_sliderFillAmount);

        // Calculate the new value and update the value text.
        Value = (int)Mathf.Lerp(_minValue, _maxValue, _sliderFillAmount);
        _sliderGraphics.UpdateValueText(Value);
    }