/// <summary> /// 播放效果音 /// </summary> public void PlayEffectAudioPrefab(EffectAudioPrefab canEffectAudioPrefab, string musicName, bool isLoopBoo = false, bool clearScene = false) { string tempPath = MUSIC_PATH + musicName; uint tempCrc = CRC32.GetCRC32(tempPath); AudioObj tempAudioObj; if (AudioAssetDic.TryGetValue(tempCrc, out tempAudioObj) && tempAudioObj != null) { canEffectAudioPrefab.m_AudioSou.clip = tempAudioObj.m_AudioClip; canEffectAudioPrefab.m_AudioSou.volume = EffectAudioVolume; canEffectAudioPrefab.m_AudioSou.loop = isLoopBoo; if (EffectAudioVolume > 0f) { canEffectAudioPrefab.m_AudioSou.Play(); } else { canEffectAudioPrefab.m_AudioSou.Stop(); } canEffectAudioPrefab.m_UsingBoo = true; } else { ResourcesMgr.Instance.AsyncLoadResource(tempPath, OnLoadEffectAssetFinish, LoadResPriority.RES_HIGHT, false, clearScene, isLoopBoo, canEffectAudioPrefab); } }
void LoadEffectAssetFinish(string path, Object obj, object param1 = null, object param2 = null, object param3 = null) { uint tempCrc = CRC32.GetCRC32(path); AudioObj tempObj = AudioObjClassPool.Spawn(true); tempObj.m_AudioClip = obj as AudioClip; tempObj.m_ClearScene = (bool)param1; AudioAssetDic.Add(tempCrc, tempObj); EffectAudioPrefab tempEff = param3 as EffectAudioPrefab; tempEff.m_AudioSou.clip = tempObj.m_AudioClip; tempEff.m_AudioSou.volume = EffectAudioVolume; tempEff.m_AudioSou.loop = (bool)param2; if (EffectAudioVolume > 0f) { tempEff.m_AudioSou.Play(); } else { tempEff.m_AudioSou.Stop(); } tempEff.m_UsingBoo = true; EffectAudioDic.Add(tempEff.m_guid, tempEff); CoroutineMgr.Instance.StartCoroutine(tempEff.m_guid, EffectAudioTimerCor(tempEff.m_guid)); }
/// <summary> /// 回收音效预置物 /// </summary> public void RecycleEffectAudioPrefab(EffectAudioPrefab canEffectAudioPrefab) { canEffectAudioPrefab.m_AudioTrs.SetParent(SoundStageTrs, false); canEffectAudioPrefab.m_AudioTrs.localPosition = new Vector3(0, 0, 0); canEffectAudioPrefab.m_ResetParentBoo = false; canEffectAudioPrefab.m_UsingBoo = false; canEffectAudioPrefab.m_AudioSou.Stop(); EffectAudioDic.Remove(canEffectAudioPrefab.m_guid); EffectAudioRecyclePool.Enqueue(canEffectAudioPrefab); }
void OnLoadEffectAssetFinish(string path, Object obj, object param1 = null, object param2 = null, object param3 = null) { uint tempCrc = CRC32.GetCRC32(path); AudioObj tempObj = AudioObjClassPool.Spawn(true); tempObj.m_AudioClip = obj as AudioClip; tempObj.m_ClearScene = (bool)param1; AudioAssetDic.Add(tempCrc, tempObj); EffectAudioPrefab tempEff = param3 as EffectAudioPrefab; tempEff.m_AudioSou.clip = tempObj.m_AudioClip; tempEff.m_AudioSou.volume = EffectAudioVolume; if (EffectAudioVolume > 0f) { tempEff.m_AudioSou.Play(); } else { tempEff.m_AudioSou.Stop(); } tempEff.m_UsingBoo = true; }