private Dictionary <int, SoundClip> m_SoundClipMap = new Dictionary <int, SoundClip>(); //ÒôЧÁÐ±í£¬ÏÞÖÆ×î´óÊýÁ¿MAX /// <summary> /// ¸ù¾ÝÉùÒôÃû³ÆµÃµ½SoundClip£¬²»´æÔÚ»á×Ô¶¯Ìí¼Ó /// </summary> /// <param name="name">Ãû³Æ</param> /// <returns></returns> public void GetSoundClip(int nSoundId, GetSoundClipDelegate delFun, SoundClipParam param) { if (nSoundId >= 0) { if (m_SoundClipMap.ContainsKey(nSoundId)) { //¸üÐÂÉϴβ¥·Åʱ¼ä m_SoundClipMap[nSoundId].m_LastActiveTime = Time.realtimeSinceStartup; if (null != delFun) { delFun(m_SoundClipMap[nSoundId], param); } return; } else { if (m_SoundClipMap.Count > SoundManager.m_SFXChannelsCount) //³¬¹ý×î´óÖµ£¬É¾³ý×ʱ¼äδʹÓÃµÄ { //LogModule.DebugLog("Warnning m_SoundClipList.Count > " + SoundManager.m_SFXChannelsCount); RemoveLastUnUsedClip(); } Tab_Sounds soundsTab = TableManager.GetSoundsByID(nSoundId, 0); if (soundsTab == null) { LogModule.DebugLog("sound id " + nSoundId.ToString() + " is null"); if (null != delFun) { delFun(null, param); } return; } string fullsoundName = soundsTab.FullPathName; if (string.IsNullOrEmpty(fullsoundName)) { if (null != delFun) { delFun(null, param); } return; } if (GameManager.gameManager.SceneLogic == null) { if (null != delFun) { delFun(null, param); } return; } GameManager.gameManager.SceneLogic.StartCoroutine(BundleManager.LoadSound(fullsoundName, OnLoadSound, soundsTab, delFun, param)); } } }
/// <summary> /// 根据声音名称得到SoundClip,不存在会自动添加 /// </summary> /// <param name="name">名称</param> /// <returns></returns> public void GetSoundClip(int nSoundId, GetSoundClipDelegate delFun, SoundClipParam param, bool reset) { if (nSoundId >= 0) { if (m_SoundClipMap.ContainsKey(nSoundId)) { //更新上次播放时间 m_SoundClipMap[nSoundId].m_LastActiveTime = Time.realtimeSinceStartup; if (null != delFun) { delFun(m_SoundClipMap[nSoundId], param, reset); } } else { if (m_SoundClipMap.Count > SoundManager.mSFXChannelsCount) //超过最大值,删除最长时间未使用的 { RemoveLastUnUsedClip(); } var soundsTab = Table.GetSound(nSoundId); if (soundsTab == null) { Logger.Info("sound id " + nSoundId + " is null"); if (null != delFun) { delFun(null, param, reset); } return; } var fullsoundName = soundsTab.FullPathName; if (string.IsNullOrEmpty(fullsoundName)) { if (null != delFun) { delFun(null, param, reset); } return; } if (ResourceManager.Instance == null) { if (null != delFun) { delFun(null, param, reset); } return; } ResourceManager.PrepareSoundResource(fullsoundName, OnLoadSound, soundsTab, delFun, param); } } }
void OnLoadSound(string soundPath, AudioClip curAudioClip, object param1, object param2, object param3 = null) { SoundClip clip = new SoundClip(); clip.Audioclip = curAudioClip; GetSoundClipDelegate delFun = param2 as GetSoundClipDelegate; SoundClipParam soundClipParam = param3 as SoundClipParam; Tab_Sounds soundsTab = param1 as Tab_Sounds; if (null == clip.Audioclip) { LogModule.DebugLog("sound clip " + soundPath + " is null"); if (null != delFun) { delFun(null, soundClipParam); } return; } if (!clip.Audioclip.isReadyToPlay) { LogModule.DebugLog("Cann't decompress the sound resource " + soundPath); if (null != delFun) { delFun(null, soundClipParam); } return; } clip.m_LastActiveTime = Time.realtimeSinceStartup; clip.m_delay = soundsTab.Delay; clip.m_minDistance = soundsTab.MinDistance; clip.m_panLevel = soundsTab.PanLevel; clip.m_spread = soundsTab.Spread; clip.m_volume = soundsTab.Volume; clip.m_isLoop = soundsTab.IsLoop; clip.m_path = soundPath; clip.m_name = soundsTab.Name; clip.m_uID = (short)soundsTab.Id; clip.m_curMaxPlayingCount = soundsTab.CurMaxPlayingCount; if (!m_SoundClipMap.ContainsKey(soundsTab.Id)) { m_SoundClipMap.Add(soundsTab.Id, clip); } if (null != delFun) { delFun(clip, soundClipParam); } }