Exemple #1
0
 public override void DoUpdate()
 {
     for (_i = 0, _leni = _playingSoundEffectConfigList.Count; _i < _leni; _i++)
     {
         for (_j = 0, _lenj = mPlayingSoundEffectDict[_playingSoundEffectConfigList[_i]].Count; _j < _lenj; _j++)
         {
             _audio = mPlayingSoundEffectDict[_playingSoundEffectConfigList[_i]][_j];
             if (_audio.state == E_AudioPlayState.Sleeping)
             {
                 mPlayingSoundEffectDict[_playingSoundEffectConfigList[_i]].RemoveAt(_j);
                 _j--;
                 _lenj--;
                 _audio.DoClean();
                 _idleAudioUnitList.Add(_audio);
                 if (mPlayingSoundEffectDict[_playingSoundEffectConfigList[_i]].Count == 0)
                 {
                     mPlayingSoundEffectDict.Remove(_playingSoundEffectConfigList[_i]);
                     _playingSoundEffectConfigList.RemoveAt(_i);
                     _i--;
                     _leni--;
                 }
             }
             else
             {
                 _audio.DoUpdate();
             }
         }
     }
     if (_single_music != null)
     {
         _single_music.DoUpdate();
     }
 }
Exemple #2
0
        /// <summary>
        /// 恢复播放
        /// </summary>
        /// <param name="configID"></param>
        /// <param name="audioInfo"></param>
        public void Resume(MAudioIdType configID, MAudio audioInfo = null)
        {
            if (_single_music != null && _single_music.audioId == configID)
            {
                _single_music.Resume();
                return;
            }
            var L = mPlayingSoundEffectDict.GetList();

            for (int i = 0, count = L.Count; i < count; i++)
            {
                var kv = L[i];
                if (kv.Key == configID)
                {
                    var ValueList = kv.Value;
                    if (audioInfo != null)
                    {
                        for (int j = 0, VCount = ValueList.Count; j < VCount; j++)
                        {
                            if (audioInfo == ValueList[j])
                            {
                                ValueList[j].Resume();
                            }
                        }
                    }
                    else
                    {
                        for (int j = 0, VCount = ValueList.Count; j < VCount; j++)
                        {
                            ValueList[j].Resume();
                        }
                    }
                }
            }
        }
Exemple #3
0
        }     //end fun

        /// <summary>
        /// 离开玩法场景的时候 ,统一清除一遍
        /// </summary>
        public override void DoDestroy()
        {
            DestroyEffect();
            if (_single_music != null)
            {
                _single_music.DoDestroy();
            }
            _single_music = null;

            GameCache.Instance.audioPool.Clear();
            GameCache.Instance.AudioObjectPool.Clear();
            base.DoDestroy();
        }
Exemple #4
0
        /// <summary>

        /// <summary>
        /// 播放 ,音频id 和父对象tf ,对应audioresconfig 表格的id
        /// </summary>
        /// <param name="configID"></param>
        /// <param name="tf"></param>
        public MAudio Play(MAudioIdType configID, Transform tf, float durationTime, int audioType,
                           bool loop, int loopCount)
        {
            MAudioIdType configId = configID;

            List <MAudio> mPlayingList;

            if (mPlayingSoundEffectDict.TryGetValue(configId, out mPlayingList))
            {
                if (mPlayingList == null)
                {
                    mPlayingList = new List <MAudio>();
                    mPlayingSoundEffectDict[configId] = mPlayingList;
                }
            }
            else
            {
                mPlayingList = new List <MAudio>();
                mPlayingSoundEffectDict.Add(configId, mPlayingList);
                _playingSoundEffectConfigList.Add(configId);
            }
            var mAudioType = audioType;

            if (mAudioType == E_MAudioType.LOADING_AUDIO || mAudioType == E_MAudioType.BGM)//TODO:改为音效类型
            {
                // 处于loading时期 ,禁止播放其他类型音效,避免野指针

                if (_single_music == null)
                {
                    _single_music = MAudio.Get();
                }
                _single_music.AttachAudioObject(configId, tf, durationTime, audioType, loop, loopCount);
                return(_single_music);
            }
            else
            {
                // 处于loading时期 ,禁止播放其他类型音效,避免野指针
                //音效//
                if (mPlayingList.Count < maxOverlay)
                {
                    MAudio audio = null;
                    audio = MAudio.Get();
                    if (audio.state != E_AudioPlayState.Sleeping)
                    {
                        audio = null;
                        audio = MAudio.Get();
                    }
                    mPlayingSoundEffectDict[configId].Add(audio);
                    audio.AttachAudioObject(configId, tf, durationTime, audioType, loop, loopCount);
                    return(audio);
                }
                else
                {
                    for (int i = 0, count = mPlayingList.Count; i < count; i++)
                    {
                        var A = mPlayingList[i];
                        if (A.state == E_AudioPlayState.Pause)
                        {
                            A.Resume();
                            return(A);
                        }
                        else if (A.state == E_AudioPlayState.Sleeping)
                        {
                            A.Play(true);
                            return(A);
                        }
                    }

                    return(null);
                }
            }
        }