private IEnumerator PlayInstanceImplement(IndependentAudio audio) { yield return(new WaitForSecondsRealtime(audio.Source.clip.length)); this.audioQualityDic[audio.Name]--; Destroy(audio.Source); }
public void PlayInstance(string name) { var value = 0; if (this.audioQualityDic.TryGetValue(name, out value)) { if (value > 3) { return; } } else { this.audioQualityDic.Add(name, 0); } //if (this.audioQualityDic.ContainsKey(name)) //{ // if (this.audioQualityDic[name] > 3) // return; //} //else this.audioQualityDic.Add(name, 0); this.audioQualityDic[name]++; var audioPrefab = this.Audios.Find(a => name == a.Name); if (audioPrefab == null) { Debug.LogWarning("未找到指定名称的音频。"); return; } var audio = new IndependentAudio(); audio.Name = name; audio.Source = this.gameObject.AddComponent <AudioSource>(); audio.Source.clip = audioPrefab.Clip; audio.Source.outputAudioMixerGroup = audioPrefab.AMG; audio.Source.pitch = audioPrefab.Pitch; audio.Source.volume = audioPrefab.Volume; audio.Source.loop = audioPrefab.IsLoop; audio.Source.Play(); StartCoroutine(PlayInstanceImplement(audio)); }