private void stopBGMPlayed(AudioSource audio, ClipDetail clipDetail, AudioLoopCallbacks callback, bool immediatly) { if (!audio) { return; } if (immediatly) { audio.volume = 0; audio.Stop(); audio.clip = null; callback?.Unsubscribe(); } else { DOVirtual.Float(1, 0, timeFade, (x) => { audio.volume = globalBGMVolume * clipDetail.localVolume * x; }).OnComplete(() => { audio.volume = 0; audio.Stop(); audio.clip = null; callback?.Unsubscribe(); }); } }
private void stopBGMPlayed(string audioSource, bool immediatly) { var audioSourceData = audioSources.GetAudio(audioSource); AudioSource audio = audioSourceData.audio; AudioLoopCallbacks callback = audioSourceData.callback; Debug.Log(audio + " " + audioSourceData); if (!audio || !audio.isPlaying) { return; } if (immediatly) { audio.volume = 0; audio.Stop(); audio.clip = null; callback?.Unsubscribe(); } else { ClipDetail clipDetail = audioLibrary.GetBGMClip(audio.clip); DOVirtual.Float(1f, 0f, timeFade, (x) => { audio.volume = globalBGMVolume * clipDetail.localVolume * x; }).OnComplete(() => { audio.volume = 0; audio.Stop(); audio.clip = null; callback?.Unsubscribe(); }); } }
/// <summary> /// This is the method to make looping at specific track session with intro first time /// Will be seen when the start loop time is not the start time of the clip /// </summary> private void OnLoopWithIntro_Callbacks() { try { if (source.loop) { source.loop = false; } float clipTime = source.time; float maxTime = source.clip.length; if (!source.isPlaying) { source.Play(); } if (CheckTimeLoop()) { source.Stop(); return; } if (clipTime >= end) { source.time = start; } } catch (NullReferenceException er) { Debug.LogWarning("The Audio Source is dont have clip attached" + er.Message); callbacks.Unsubscribe(OnLoopWithIntro_Callbacks); } catch (UnassignedReferenceException erRefference) { Debug.LogWarning("The Audio Source is null" + erRefference.Message); callbacks.Unsubscribe(OnLoopWithIntro_Callbacks); } }