public void PlaySceneMusic() { if (null == GameManager.gameManager.SoundManager) { return; } Tab_SceneClass tab = TableManager.GetSceneClassByID(GameManager.gameManager.RunningScene, 0); if (tab == null) { return; } if (tab.BGMusic < 0) { return; } Tab_Sounds soundsTab = TableManager.GetSoundsByID(tab.BGMusic, 0); if (soundsTab == null) { LogModule.DebugLog("sound name " + tab.BGMusic.ToString() + " is null"); return; } GameManager.gameManager.SoundManager.PlayBGMusic(tab.BGMusic, soundsTab.FadeOutTime, soundsTab.FadeInTime); }
public uint Execute(PacketDistributed ipacket) { GC_PLAY_SOUNDS packet = (GC_PLAY_SOUNDS )ipacket; if (null == packet) { return((uint)PACKET_EXE.PACKET_EXE_ERROR); } //enter your logic Tab_Sounds soundsTab = TableManager.GetSoundsByID(packet.SoundID, 0); if (soundsTab == null) { //LogModule.DebugLog("GC_PLAY_SOUNDSHandler sound name " + packet.SoundName + " is null"); return((uint)PACKET_EXE.PACKET_EXE_CONTINUE); } if (packet.SoundType == (int)GC_PLAY_SOUNDS.SOUNDTYPE.SOUND_EFFECT) { GameManager.gameManager.SoundManager.PlaySoundEffect(packet.SoundID); } else if (packet.SoundType == (int)GC_PLAY_SOUNDS.SOUNDTYPE.SOUND_SCENE) { GameManager.gameManager.SoundManager.PlayBGMusic(packet.SoundID, soundsTab.FadeOutTime, soundsTab.FadeInTime); } return((uint)PACKET_EXE.PACKET_EXE_CONTINUE); }
/// <summary> /// ɾ³ý×ʱ¼äδʹÓõÄÌõÄ¿ /// </summary> private void RemoveLastUnUsedClip() { float fSmallestTime = 99999999.0f; int smallestId = -1; foreach (SoundClip clip in m_SoundClipMap.Values) { if (fSmallestTime > clip.m_LastActiveTime) { smallestId = clip.m_uID; fSmallestTime = clip.m_LastActiveTime; } } LogModule.DebugLog("RemoveLastUnUsedClip( " + smallestId.ToString() + " )"); //ÒÔºó×¢Ê͵ô m_SoundClipMap.Remove(smallestId); #if UNITY_WP8 Tab_Sounds soundsTab = TableManager.GetSoundsByID(smallestId, 0); if (null != soundsTab) { BundleManager.ReleaseUnreferencedSoundBundle(BundleManager.GetBundleLoadUrl("", soundsTab.FullPathName + ".data")); } #endif }
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)); } } }
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); } }
//add by sunyu 2014-07-31 //force Remove clip from pool, special for bgmusic public void ForceRemoveClipByID(short uid) { if (uid != -1) { int nNeeddelId = -1; foreach (SoundClip clip in m_SoundClipMap.Values) //dictionary µÄ foreachÈ¥²»µô { if (clip.m_uID == uid) { nNeeddelId = clip.m_uID; break; } } m_SoundClipMap.Remove(nNeeddelId); #if UNITY_WP8 Tab_Sounds soundsTab = TableManager.GetSoundsByID(nNeeddelId, 0); if (null != soundsTab) { BundleManager.ReleaseUnreferencedSoundBundle(BundleManager.GetBundleLoadUrl("", soundsTab.FullPathName + ".data")); } #endif } }