Пример #1
0
        public void PlayEffectAudio(string musicName, bool is3DBoo, Vector3 canVector3, Transform canTrs = null, 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)
            {
                EffectAudioPrefab tempEffectPrefabObj;
                if (EffectAudioRecyclePool.Count > 0)
                {
                    tempEffectPrefabObj = EffectAudioRecyclePool.Dequeue();
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    tempEffectPrefabObj.m_AudioTrs.transform.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou.spatialBlend            = is3DBoo ? 1 : 0;
                    tempEffectPrefabObj.m_AudioSou.clip   = tempAudioObj.m_AudioClip;
                    tempEffectPrefabObj.m_AudioSou.volume = EffectAudioVolume;
                    tempEffectPrefabObj.m_AudioSou.loop   = isLoopBoo;
                    if (EffectAudioVolume > 0f)
                    {
                        tempEffectPrefabObj.m_AudioSou.Play();
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioSou.Stop();
                    }
                    tempEffectPrefabObj.m_UsingBoo = true;
                    EffectAudioDic.Add(tempEffectPrefabObj.m_guid, tempEffectPrefabObj);
                }
                else
                {
                    tempEffectPrefabObj        = EffectAudioClassPool.Spawn(true);
                    tempEffectPrefabObj.m_guid = GetEffectAudioGuid();
                    GameObject tempObj = new GameObject(tempEffectPrefabObj.m_guid + "_Stage");
                    tempEffectPrefabObj.m_AudioTrs = tempObj.transform;
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(SoundStageTrs, false);
                    }
                    tempEffectPrefabObj.m_AudioTrs.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou = tempObj.AddComponent <AudioSource>();
                    tempEffectPrefabObj.m_AudioSou.spatialBlend = is3DBoo ? 1 : 0;
                    tempEffectPrefabObj.m_AudioSou.volume       = EffectAudioVolume;
                    tempEffectPrefabObj.m_AudioSou.clip         = tempAudioObj.m_AudioClip;
                    tempEffectPrefabObj.m_AudioSou.loop         = isLoopBoo;
                    if (EffectAudioVolume > 0f)
                    {
                        tempEffectPrefabObj.m_AudioSou.Play();
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioSou.Stop();
                    }
                    tempEffectPrefabObj.m_UsingBoo = true;
                    EffectAudioDic.Add(tempEffectPrefabObj.m_guid, tempEffectPrefabObj);
                    CoroutineMgr.Instance.StartCoroutine(tempEffectPrefabObj.m_guid, EffectAudioTimerCor(tempEffectPrefabObj.m_guid));
                }
            }
            else
            {
                EffectAudioPrefab tempEffectPrefabObj;
                if (EffectAudioRecyclePool.Count > 0)
                {
                    tempEffectPrefabObj = EffectAudioRecyclePool.Dequeue();
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    tempEffectPrefabObj.m_AudioTrs.transform.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou.spatialBlend            = is3DBoo ? 1 : 0;
                }
                else
                {
                    tempEffectPrefabObj        = EffectAudioClassPool.Spawn(true);
                    tempEffectPrefabObj.m_guid = GetEffectAudioGuid();
                    GameObject tempObj = new GameObject(tempEffectPrefabObj.m_guid + "_Stage");
                    tempEffectPrefabObj.m_AudioTrs = tempObj.transform;
                    if (canTrs)
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(canTrs, false);
                        tempEffectPrefabObj.m_ResetParentBoo = true;
                    }
                    else
                    {
                        tempEffectPrefabObj.m_AudioTrs.SetParent(SoundStageTrs, false);
                    }
                    tempEffectPrefabObj.m_AudioTrs.localPosition = canVector3;
                    tempEffectPrefabObj.m_AudioSou = tempObj.AddComponent <AudioSource>();
                    tempEffectPrefabObj.m_AudioSou.spatialBlend = is3DBoo ? 1 : 0;
                }
                ResourcesMgr.Instance.AsyncLoadResource(tempPath, LoadEffectAssetFinish, LoadResPriority.RES_HIGHT, false, clearScene, isLoopBoo, tempEffectPrefabObj);
            }
        }