public static void PlayClip(AudioClip clip, LoopGroup group) { var go = EditorUtility.CreateGameObjectWithHideFlags("PLAY_AUDIO_TEMP", HideFlags.HideAndDontSave); var source = go.AddComponent <AudioSource> (); source.clip = clip; source.volume = UnityEngine.Random.Range(group.VolumeRange.x, group.VolumeRange.y); source.pitch = UnityEngine.Random.Range(group.PitchRange.x, group.PitchRange.y); source.Play(); source.loop = true; EditorCoroutine.Start(TurnOffAfter(source, group)); }
public void PlayClip(LoopGroup group, EffectFader fader) { var source = Pool.Grab(); source.clip = group.LoopedAudio; source.pitch = group.PitchRange.x; source.volume = group.VolumeRange.x; source.loop = true; var animator = new AudioSourceAnimator(source, TabFade, MasterVolume, SfxVolume); Animators.Add(animator); source.Play(); StartCoroutine(ManageLoop(animator, group, fader)); }
private static IEnumerator TurnOffAfter(AudioSource source, LoopGroup group) { float startTime = Time.realtimeSinceStartup + 1.5f; while (startTime > Time.realtimeSinceStartup) { source.volume = Mathf.Lerp(group.VolumeRange.x, group.VolumeRange.y, Mathf.PerlinNoise(0.313f, Time.realtimeSinceStartup * group.PerlinSpeed)); source.pitch = Mathf.Lerp(group.PitchRange.x, group.PitchRange.y, Mathf.PerlinNoise(0.83f, Time.realtimeSinceStartup * group.PerlinSpeed)); yield return(null); } source.Stop(); DestroyImmediate(source.gameObject); }
public static void Play(LoopGroup group, EffectFader fader) { instance.PlayClip(group, fader); }