private void Update() { if (this.CanPlaySoundEffect()) { for (int i = 0; i < this.intervalAudioList.Count; i++) { SoundManager.IntervalAudio intervalAudio = this.intervalAudioList[i]; if (this.IsTimeTo(intervalAudio)) { this.Play2DAduio(intervalAudio.audioPath, true); } } } if (this.CanPlayBackSound() && this.intervalBackgroundMusic != null && this.IsTimeTo(this.intervalBackgroundMusic)) { if (this.bgAudio.isPlaying) { this.intervalBackgroundMusic.intervalTime = (float)this.intervalBackgroundMusic.intervalBackTime; this.bgAudio.Stop(); } else { this.PlayBackgroundIntervalPlayAduio(this.intervalBackgroundMusic.audioPath, this.intervalBackgroundMusic.intervalBackTime); } } }
private bool IsTimeTo(SoundManager.IntervalAudio intervalAudio) { intervalAudio.sumDeltaTime += Time.deltaTime; if (intervalAudio.sumDeltaTime > intervalAudio.intervalTime) { intervalAudio.sumDeltaTime = 0f; return(true); } return(false); }
public void Play2DIntervalPlayAduio(string path, float min, float max) { SoundManager.IntervalAudio intervalAudio = new SoundManager.IntervalAudio(); intervalAudio.audioPath = path; this.LoadAudioClip(path, delegate(AudioClip ac) { intervalAudio.intervalTime = ac.length + UnityEngine.Random.Range(min, max); intervalAudio.sumDeltaTime = intervalAudio.intervalTime; this.intervalAudioList.Add(intervalAudio); }); }
public void PlayBackgroundIntervalPlayAduio(string path, int intervalTime) { if (this.intervalBackgroundMusic == null) { this.intervalBackgroundMusic = new SoundManager.IntervalAudio(); } this.intervalBackgroundMusic.audioPath = path; this.intervalBackgroundMusic.sumDeltaTime = 0f; this.intervalBackgroundMusic.intervalBackTime = intervalTime; this.playBackSound(path, true, this.intervalBackgroundMusic); }
private void playBackSound(string path, bool isLoop, SoundManager.IntervalAudio _intervalBackgroundMusic) { this.LoadAudioClip(path, delegate(AudioClip ac) { if (ac != null) { this.bgAudio.Stop(); if (!isLoop) { this.bgAudio.clip = null; if (!this.CanPlayBackSound()) { return; } this.bgAudio.PlayOneShot(ac); } else { this.intervalBackgroundMusic = _intervalBackgroundMusic; if (this.intervalBackgroundMusic != null) { this.intervalBackgroundMusic.intervalTime = ac.length; } this.bgAudio.clip = ac; this.bgAudio.loop = true; if (!this.CanPlayBackSound()) { this.bgAudio.Play(); this.bgAudio.Pause(); this.bgAudio.enabled = false; } else { this.bgAudio.enabled = true; this.bgAudio.Play(); } } } }); }
public void CleanAudioClip() { if (this.sounds.Count > 0) { List <string> list = new List <string>(); Dictionary <string, AudioClip> .Enumerator enumerator = this.sounds.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <string, AudioClip> current = enumerator.Current; string text = current.Key.Replace('/', '_'); if (text.LastIndexOf('.') != -1) { text = text.Substring(0, text.LastIndexOf('.')); } UnityEngine.Object arg_7B_0 = this.bgAudio.clip; KeyValuePair <string, AudioClip> current2 = enumerator.Current; if (arg_7B_0 != current2.Value) { List <string> arg_96_0 = list; KeyValuePair <string, AudioClip> current3 = enumerator.Current; arg_96_0.Add(current3.Key); base.ResManager.UnloadAssetBundle(text, true, true); } } for (int i = 0; i < list.Count; i++) { if (this.sounds.ContainsKey(list[i]) && this.sounds[list[i]] == null) { this.sounds.Remove(list[i]); } } list.Clear(); } this.onlyAudio.Stop(); this.onlyAudio.clip = null; this.intervalBackgroundMusic = null; this.ClearIntervalPlayAduio(); this.Stop2DAduio(); Util.ClearMemory(); }
public void StopBackSound() { this.bgAudio.Stop(); this.intervalBackgroundMusic = null; }