private IEnumerator RunFadeVolume(VolumeFadeParameters parameters) { float t; t = 0; float frameRate; frameRate = (Application.targetFrameRate > 0) ? Application.targetFrameRate : 60; float step; step = 1 / (frameRate * parameters.Duration); this.Volume = parameters.From; while (t < 1) { yield return(null); t = Mathf.Clamp(t + step, 0, 1); this.Volume = Quadratic.EaseInOut(parameters.From, parameters.To, t); } if (parameters.Completion != null) { parameters.Completion(this); } }
public void FadeVolume(float from, float to, float duration, AudioPlayer.Delegate completionDelegate) { string coroutine; coroutine = "RunFadeVolume"; VolumeFadeParameters parameters; parameters = new VolumeFadeParameters() { Completion = completionDelegate, Duration = duration, From = (from >= 0) ? from : this.Volume, To = to }; StopCoroutine(coroutine); StartCoroutine(coroutine, parameters); }
public void FadeVolume(float from, float to, float duration, Delegate completionDelegate) { if (!this.gameObject.activeInHierarchy) { return; } VolumeFadeParameters parameters; parameters = new VolumeFadeParameters() { Completion = completionDelegate, Duration = duration, From = (from >= 0) ? from : this.Volume, To = to }; StopCoroutine(FADE_VOLUME_COROUTINE); StartCoroutine(FADE_VOLUME_COROUTINE, parameters); }