Example #1
0
            public void Initialize(PlayerFoleyAsset foley)
            {
                _time      = foley ? foley.breathing.GetInitialDelay() : 0f;
                _period    = 0f;
                _state     = 1;
                _pace      = 0f;
                _intensity = 0f;

                _setType      = BreathType.Normal;
                _setPace      = 0f;
                _setIntensity = 0f;
            }
Example #2
0
            public bool Update(
                PlayerFoleyAsset foley, float intensity, BreathType type, bool isJumping,
                out AxelF.Patch asset, out float volume)
            {
                if (foley && _state != 0)
                {
                    float deltaTime = Time.deltaTime;

                    if (isJumping)
                    {
                        deltaTime = 0f; // infinite time dilation when jumping to synchronize landing
                    }
                    _intensity += (intensity - foley.breathing.intensityDampening) * deltaTime;
                    _intensity  = Mathf.Clamp01(_intensity);

                    _pace = Mathf.Lerp(
                        _pace, _intensity * _intensity * _intensity,
                        deltaTime * foley.breathing.intensityTransference);

                    _period = foley.breathing.GetBreathingPeriod() -
                              _intensity * foley.breathing.breathingPeriodIntensityFactor;

                    _time -= deltaTime / _period;

                    if (_time <= 0f)
                    {
                        if (inhaling)
                        {
                            _time         = foley.breathing.GetExhalePeriod();
                            _setType      = type;
                            _setPace      = _pace;
                            _setIntensity = _intensity;
                        }
                        else
                        {
                            _time  = foley.breathing.GetInhalePeriod();
                            _time -= _time * _setPace * foley.breathing.inhalePeriodPacingFactor;
                        }
                        asset  = foley.breathing.GetAsset(_setType, _setPace, _setIntensity, inhaling);
                        volume = foley.breathing.GetVolumeOverPace();
                        volume = Mathf.Clamp01(volume + _pace * volume);
                        _state = -_state;
                        return(true);
                    }
                }
                asset  = null;
                volume = 0f;
                return(false);
            }