public void playAllSoundEff(bool isSound) { foreach (KeyValuePair <string, Dictionary <string, GTAudioSource> > oneVaArr in catchAudio) { Dictionary <string, GTAudioSource> oneSortArr = oneVaArr.Value; foreach (KeyValuePair <string, GTAudioSource> oneVa in oneSortArr) { GTAudioSource sourceOld = oneVa.Value; if (sourceOld != null && sourceOld.source != null && sourceOld.isSound == isSound) { sourceOld.source.Play(); } } } }
public void stopEff(string key, string sortName) { string nameStr = sortName + "_" + key; if (catchAudio.ContainsKey(sortName)) { Dictionary <string, GTAudioSource> oneSortArr = catchAudio [sortName]; if (oneSortArr != null && oneSortArr.ContainsKey(key)) { GTAudioSource sourceOld = oneSortArr [key]; if (sourceOld != null && sourceOld.source != null) { sourceOld.source.Stop(); oneSortArr.Remove(key); GameObject.Destroy(sourceOld.source.gameObject); } } } // yield return null; }
public void stopOneSortEff(string sortName) { if (catchAudio.ContainsKey(sortName)) { Dictionary <string, GTAudioSource> oneSortArr = catchAudio [sortName]; if (oneSortArr != null) { foreach (KeyValuePair <string, GTAudioSource> oneVa in oneSortArr) { GTAudioSource sourceOld = oneVa.Value; if (sourceOld != null && sourceOld.source != null) { sourceOld.source.Stop(); GameObject.Destroy(sourceOld.source.gameObject); } } catchAudio [sortName] = new Dictionary <string, GTAudioSource> (); } } // yield return null; }
IEnumerator playSoundEff(string key, string sortName, float vol, ulong delay, bool bLoop, bool isSound) { if (m_EffPlayFlag == false) { yield break; } ClipHolder holder = new ClipHolder(); yield return(StartCoroutine(loadAudioFromCache(key, sortName, holder))); if (holder.clip == null) { yield break; } string nameStr = sortName + "_" + key; if (!catchAudio.ContainsKey(sortName)) { catchAudio [sortName] = new Dictionary <string, GTAudioSource> (); } Dictionary <string, GTAudioSource> oneSortArr = catchAudio [sortName]; if (oneSortArr != null) { if (oneSortArr.ContainsKey(key)) { GTAudioSource sourceOld = oneSortArr [key]; if (sourceOld != null) { if (vol < 0.0f) { vol = 0.1f; } if (isSound) { sourceOld.source.volume = GameSet.bSoundvolume * vol; } else { sourceOld.source.volume = GameSet.bMusicOnvolume * vol; } //if (vol < 0.0f) //{ // sourceOld.source.volume = 0.1f; //} //else //{ // sourceOld.source.volume = vol; //} if (delay != 0) { sourceOld.source.Play(delay); } else { sourceOld.source.Play(); } sourceOld.source.loop = !isSound; if (!GameSet.bSoundOn) { sourceOld.source.Stop(); } } } else { GameObject obj = new GameObject(key); obj.transform.parent = gameObject.transform; AudioSource source = obj.AddComponent <AudioSource> (); GTAudioSource newSource = new GTAudioSource(); newSource.sortName = sortName; newSource.sortKey = key; newSource.isSound = isSound; if (source != null && holder != null && holder.clip != null) { source.clip = holder.clip; newSource.source = source; oneSortArr [key] = newSource; source.loop = bLoop; if (vol < 1f) { vol = 1f; } if (isSound) { source.volume = GameSet.bSoundvolume * vol; } else { source.volume = GameSet.bMusicOnvolume * vol; } //if (vol < 1.0f) //{ // source.volume = 1.0f; //} //else //{ // source.volume = vol; //} if (delay != 0) { source.Play(delay); } else { source.Play(); } source.loop = !isSound; if (!GameSet.bSoundOn) { source.Stop(); } } else { catchAudio.Remove(key); GameObject.Destroy(obj); } } } }