void LoadSoundAssetSuccess(string path, object[] userdata, AudioClip audioAsset, OnAssetDestory onDestory) { int soundId = (int)userdata[0]; SoundTableSetting soundTable = (SoundTableSetting)userdata[1]; SoundGroup soundGroup = dicSoundGroups[soundTable.Group]; PlaySoundParams soundParams = new PlaySoundParams(); soundParams.Time = soundTable.Time; soundParams.MuteInSoundGroup = Constant.DefaultMute; soundParams.Loop = soundTable.Loop; soundParams.Priority = soundTable.Priority; soundParams.VolumeInSoundGroup = Constant.DefaultVolume; soundParams.FadeInSeconds = soundTable.FadeInSeconds; soundParams.FadeOutSeconds = soundTable.FadeOutSeconds; soundParams.Pitch = soundTable.Pitch; soundParams.PanStereo = soundTable.PanStereo; soundParams.SpatialBlend = soundTable.SpatialBlend; soundParams.MaxDistance = soundTable.MaxDistance; PlaySoundErrorCode?errCode; soundGroup.PlaySound(soundId, audioAsset, soundParams, onDestory, out errCode); if (errCode != null) { Debug.LogError(soundId + " PlaySoundErrorCode=>" + errCode.ToString()); } }
void LoadSoundAssetAndPlay(int soundId) { if (soundId == 0) { return; } SoundTableSetting soundTable = SoundTableSettings.Get(soundId); string path = string.Format("Sound/{0}{1}", soundTable.Path, (ResourceManager.EditorMode ? "." + soundTable.Extension : ResourceManager.BUNDLE_SUFFIX)); ResourceManager.LoadSound(path, LoadSoundAssetSuccess, LoadSoundAssetFaild, soundId, soundTable); }
//public IEnumerator Init() //{ // ResourceManager.LoadAudioMixer("Sound/Mixer/Main"); // allMixGroup //} public void Play(int soundId) { if (soundId == 0) { return; } SoundTableSetting soundTable = SoundTableSettings.Get(soundId); if (soundTable == null) { Debug.LogError("soundtable doesn't exist id = " + soundId); return; } SoundGroup soundGroup = dicSoundGroups[soundTable.Group]; if (soundGroup == null) { Debug.LogError("soundGroup [" + soundTable.Group + "] doesn't exist!id = " + soundId); return; } if (soundGroup.Name == VOICE_GROUP_KEY) { if (currentVoice == 0) { currentVoice = soundId; LoadSoundAssetAndPlay(soundId); } else { queueVoice.Clear(); queueVoice.Enqueue(soundId); } return; } LoadSoundAssetAndPlay(soundId); }