private void LoadSound(ESound2DType audioType, Action onLoadOver, params lhConfigData.AudioConfig.AudioData[] arr) { string[] sound2DArr = new string[arr.Length]; for (int j = 0; j < arr.Length; j++) { sound2DArr[j] = arr[j].clipPath; } lhResources.Load(sound2DArr, (i, s, o) => { var audioData = arr[i]; var audioSource = m_defaultParent.gameObject.AddComponent <AudioSource>(); audioSource.playOnAwake = false; audioSource.clip = o as AudioClip; audioSource.outputAudioMixerGroup = mixerDic[audioData.mixerName].FindMatchingGroups(audioData.mixerGroup)[0]; if (!sound2DLibrary.ContainsKey(audioType)) { var dic = new Dictionary <string, AudioSource>(); dic.Add(audioData.name, audioSource); sound2DLibrary.Add(audioType, dic); } else { sound2DLibrary[audioType].Add(audioData.name, audioSource); } }, onLoadOver); }
public static void Play2D(ESound2DType audioType, string name) { if (!m_instance.sound2DLibrary.ContainsKey(audioType)) { lhDebug.LogError("LaoHan: dont has this audioType: " + audioType); return; } if (!m_instance.sound2DLibrary[audioType].ContainsKey(name)) { lhDebug.LogError("LaoHan: dont has this name: " + name); return; } var audioSource = m_instance.sound2DLibrary[audioType][name]; if (audioType == ESound2DType.Sound2D) { audioSource.volume = sound2DVolume; } else { audioSource.volume = backMusicVolume; } audioSource.Play(); }