Пример #1
0
        /// <summary>
        /// On play we randomize our amplitude and frequency, trigger our haptic, and initialize real time modulation if needed
        /// </summary>
        /// <param name="position"></param>
        /// <param name="feedbacksIntensity"></param>
        protected override void CustomPlayFeedback(Vector3 position, float feedbacksIntensity = 1.0f)
        {
            if (!Active || !FeedbackTypeAuthorized || !HapticSettings.CanPlay())
            {
                return;
            }

            float amplitude = Random.Range(MinAmplitude, MaxAmplitude);
            float frequency = Random.Range(MinFrequency, MaxFrequency);

            _duration = Random.Range(MinDuration, MaxDuration);
            HapticSettings.SetGamepad();
            HapticPatterns.PlayConstant(amplitude, frequency, FeedbackDuration);

            if (UseRealTimeModulation)
            {
                _coroutine = Owner.StartCoroutine(RealtimeModulationCo());
            }
        }
Пример #2
0
 public virtual void ContinuousHapticsButton()
 {
     if (!_continuousActive)
     {
         // START
         HapticController.fallbackPreset = HapticPatterns.PresetType.LightImpact;
         HapticPatterns.PlayConstant(ContinuousAmplitude, ContinuousFrequency, ContinuousDuration);
         _timeLeft = ContinuousDuration;
         ContinuousButtonText.text   = "Stop continuous haptic pattern";
         DurationSlider.interactable = false;
         _continuousActive           = true;
         DebugAudioContinuous.Play();
     }
     else
     {
         // STOP
         HapticController.Stop();
         ResetPlayState();
     }
 }
Пример #3
0
        protected virtual void HandlePower()
        {
            _knobValue = Knob.Active ? Knob.Value : 0f;

            if (!_carStarted)
            {
                if ((_knobValue > MinimumKnobValue) && (Knob.Active))
                {
                    _carStarted       = true;
                    _carStartedAt     = Time.time;
                    _lastStartClickAt = Time.time;

                    HapticPatterns.PlayConstant(_knobValue, _knobValue, MaximumPowerDuration);
                    CarEngineAudioSource.Play();
                }
                else
                {
                    Power += Time.deltaTime * ChargingSpeed;
                    Power  = Mathf.Clamp(Power, 0f, MaximumPowerDuration);

                    if (Power == MaximumPowerDuration)
                    {
                        Knob.SetActive(true);
                        Knob._rectTransform.localScale = Vector3.one;
                        ReloadingPrompt.SetActive(false);
                    }
                    else
                    {
                        if (!Knob.Active)
                        {
                            Knob.SetValue(CarSpeed);
                        }
                    }
                }
            }
            else
            {
                if (Time.time - _carStartedAt > MaximumPowerDuration)
                {
                    _carStarted = false;
                    Knob.SetActive(false);
                    Knob._rectTransform.localScale = Vector3.one * 0.9f;
                    ReloadingPrompt.SetActive(true);
                }
                else
                {
                    if (_knobValue > MinimumKnobValue)
                    {
                        Power -= Time.deltaTime;
                        Power  = Mathf.Clamp(Power, 0f, MaximumPowerDuration);

                        HapticController.clipLevel          = _knobValue;
                        HapticController.clipFrequencyShift = _knobValue;

                        if (Power <= 0f)
                        {
                            _carStarted = false;
                            Knob.SetActive(false);
                            Knob._rectTransform.localScale = Vector3.one * 0.9f;
                            ReloadingPrompt.SetActive(true);
                            HapticController.Stop();
                        }
                    }
                    else
                    {
                        _carStarted       = false;
                        _lastStartClickAt = Time.time;
                        HapticController.Stop();
                    }
                }
            }
        }