コード例 #1
0
        public AudioAsset CreateAudioAssetByPool(GameObject gameObject, bool is3D, AudioSourceType sourceType)
        {
            AudioAsset au = new AudioAsset();

            if (audioAssetsPool.Count > 0)
            {
                au = audioAssetsPool.Dequeue();
                au.ResetData();
            }
            else
            {
                au             = new AudioAsset();
                au.audioSource = gameObject.AddComponent <AudioSource>();
            }

            au.audioSource.spatialBlend = is3D ? 1 : 0;
            au.sourceType = sourceType;

            if (sourceType == AudioSourceType.Music)
            {
                au.TotleVolume = musicVolume;
            }
            else
            {
                au.TotleVolume = sfxVolume;
            }
            return(au);
        }
コード例 #2
0
 protected void PauseMusicControl(AudioAsset au, bool isPause, float fadeTime = 0.5f)
 {
     if (isPause)
     {
         //Debug.Log("PauseMusicControl Pause : "+ au.PlayState);
         if (au.PlayState == AudioPlayState.Playing)
         {
             au.SetPlayState(AudioPlayState.Pause);
             //Debug.Log("PauseMusicControl Pause");
             AddFade(au, VolumeFadeType.FadeOut, fadeTime, 0, null, (value) =>
             {
                 //Debug.LogWarning("PauseMusicControl Pause fade CallBack");
                 value.Pause();
             }, null);
         }
     }
     else
     {
         //Debug.Log("PauseMusicControl play : "+ au.PlayState);
         if (au.PlayState == AudioPlayState.Pause)
         {
             au.Play();
             AddFade(au, VolumeFadeType.FadeIn, fadeTime, 0, null, null, null);
         }
     }
 }
コード例 #3
0
ファイル: Audio3DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
        private void ClearMoreAudioAsset(GameObject owner)
        {
            if (sfxDic.ContainsKey(owner))
            {
                List <AudioAsset> sfxList = sfxDic[owner];

                for (int i = 0; i < sfxList.Count; i++)
                {
                    sfxList[i].CheckState();
                    if (sfxList[i].PlayState == AudioPlayState.Stop)
                    {
                        tempClearList.Add(sfxList[i]);
                    }
                }

                for (int i = 0; i < tempClearList.Count; i++)
                {
                    AudioAsset asset = tempClearList[i];
                    Object.Destroy(asset.audioSource);
                    DestroyAudioAssetByPool(asset);
                    sfxList.Remove(asset);
                }
                tempClearList.Clear();
            }
        }
コード例 #4
0
ファイル: Audio3DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
        public void PlaySFX(GameObject owner, string name, float volumeScale = 1f, float delay = 0f)
        {
            AudioAsset au = GetEmptyAudioAssetFromSFXList(owner);

            PlayClip(au, name, false, volumeScale, delay);
            ClearMoreAudioAsset(owner);
        }
コード例 #5
0
ファイル: Audio2DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
        public void PlaySFX(string name, float volumeScale = 1f, float delay = 0f, float pitch = 1, string flag = "")
        {
            AudioAsset au = GetEmptyAudioAssetFromSFXList();

            au.flag = flag;
            PlayClip(au, name, false, volumeScale, delay, pitch);
        }
コード例 #6
0
ファイル: Audio2DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
 public void PauseMusic(int channel, bool isPause, float fadeTime = 0.5f)
 {
     if (bgMusicDic.ContainsKey(channel))
     {
         AudioAsset au = bgMusicDic[channel];
         PauseMusicControl(au, isPause, fadeTime);
     }
 }
コード例 #7
0
 public void UnloadClip(AudioAsset asset)
 {
     if (asset.audioSource.clip != null)
     {
         string name = asset.AssetName;
         asset.audioSource.clip = null;
         ResourcesManager.DestoryAssetsCounter(name);
     }
 }
コード例 #8
0
 public void DestroyAudioAssetByPool(AudioAsset asset)
 {
     UnloadClip(asset);
     audioAssetsPool.Enqueue(asset);
     //string name = asset.assetName;
     //asset.audioSource.clip = null;
     //ResourceManager.UnLoad(name);
     // GameObject.DestroyImmediate(asset.audioSource, true);
     //Resources.UnloadAsset(asset.audioSource.clip);
 }
コード例 #9
0
ファイル: Audio2DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
        private AudioAsset GetEmptyAudioAssetFromSFXList()
        {
            AudioAsset au = null;

            if (au == null)
            {
                au = CreateAudioAssetByPool(mono.gameObject, false, AudioSourceType.SFX);
                sfxList.Add(au);
            }
            return(au);
        }
コード例 #10
0
        public void UpdateFade()
        {
            //Debug.LogWarning("UpdateFade Count: " + fadeData.Count);
            if (fadeData.Count > 0)
            {
                foreach (var item in fadeData.Values)
                {
                    bool isComplete = false;
                    switch (item.fadeType)
                    {
                    case VolumeFadeType.FadeIn:
                        isComplete = FadeIn(item);
                        break;

                    case VolumeFadeType.FadeOut:
                        isComplete = FadeOut(item);
                        break;

                    case VolumeFadeType.FadeOut2In:
                        //Debug.Log("FadeOut2In");
                        isComplete = FadeOut2In(item);
                        break;
                    }
                    if (isComplete)
                    {
                        //Debug.Log("isComplete");
                        deleteAssets.Add(item.au);
                    }
                }

                if (deleteAssets.Count > 0)
                {
                    for (int i = 0; i < deleteAssets.Count; i++)
                    {
                        AudioAsset     au   = deleteAssets[i];
                        VolumeFadeData data = fadeData[au];
                        if (data.fadeCompleteCallBack != null)
                        {
                            data.fadeCompleteCallBack(au);
                        }

                        data.fadeCompleteCallBack    = null;
                        data.fadeOutCompleteCallBack = null;
                        catcheData.Enqueue(data);
                        //Debug.Log("Remove");
                        fadeData.Remove(au);
                    }

                    deleteAssets.Clear();
                }
            }
        }
コード例 #11
0
 protected void StopMusicControl(AudioAsset au, float fadeTime = 0.5f)
 {
     if (au.PlayState != AudioPlayState.Stop)
     {
         au.SetPlayState(AudioPlayState.Stoping);
         //Debug.Log("StopMusicControl Stop");
         AddFade(au, VolumeFadeType.FadeOut, fadeTime, 0, null, (value) =>
         {
             //Debug.LogWarning("StopMusicControl Stop fade CallBack");
             value.Stop();
         }, null);
     }
 }
コード例 #12
0
ファイル: Audio3DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
 public void PauseMusic(GameObject owner, int channel, bool isPause, float fadeTime = 0.5f)
 {
     if (owner == null)
     {
         Debug.LogError("can not Pause , owner is null");
         return;
     }
     if (bgMusicDic.ContainsKey(owner))
     {
         Dictionary <int, AudioAsset> tempDic = bgMusicDic[owner];
         if (tempDic.ContainsKey(channel))
         {
             AudioAsset au = tempDic[channel];
             PauseMusicControl(au, isPause, fadeTime);
         }
     }
 }
コード例 #13
0
        protected void PlayClip(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float pitch = 1)
        {
            if (!ResourcesConfigManager.GetIsExitRes(audioName))
            {
                Debug.LogError("不存在音频:" + audioName);
                return;
            }
            //if (au.PlayState == AudioPlayState.Playing)
            //    au.Stop();
            UnloadClip(au);
            au.AssetName = audioName;
            AudioClip ac = GetAudioClip(au.AssetName);

            au.audioSource.clip  = ac;
            au.audioSource.loop  = isLoop;
            au.audioSource.pitch = pitch;
            au.VolumeScale       = volumeScale;
            au.Play(delay);
        }
コード例 #14
0
ファイル: Audio3DPlayer.cs プロジェクト: KrazyL/SkillSystem-4
        private AudioAsset GetEmptyAudioAssetFromSFXList(GameObject owner)
        {
            AudioAsset        au      = null;
            List <AudioAsset> sfxList = null;

            if (sfxDic.ContainsKey(owner))
            {
                sfxList = sfxDic[owner];
            }
            else
            {
                sfxList = new List <AudioAsset>();
                sfxDic.Add(owner, sfxList);
            }
            if (au == null)
            {
                au = CreateAudioAssetByPool(owner, true, AudioSourceType.SFX);
                sfxList.Add(au);
            }

            return(au);
        }
コード例 #15
0
        protected void PlayMusicControl(AudioAsset au, string audioName, bool isLoop = true, float volumeScale = 1, float delay = 0f, float fadeTime = 0.5f, string flag = "")
        {
            if (au.AssetName == audioName)
            {
                au.audioSource.loop = isLoop;
                if (au.PlayState != AudioPlayState.Playing)
                {
                    AddFade(au, VolumeFadeType.FadeIn, fadeTime, delay, flag, null, null);
                    au.Play();
                }
            }
            else
            {
                if (au.PlayState != AudioPlayState.Playing)
                {
                    fadeTime = fadeTime / 2f;
                }

                AddFade(au, VolumeFadeType.FadeOut2In, fadeTime, delay, flag, null, (value) =>
                {
                    PlayClip(value, audioName, isLoop, volumeScale, delay);
                });
            }
        }
コード例 #16
0
        public void AddFade(AudioAsset au, VolumeFadeType fadeType, float fadeTime, float delay, string flag, CallBack <AudioAsset> fadeCompleteCallBack, CallBack <AudioAsset> fadeOutCompleteCallBack)
        {
            VolumeFadeData data = null;

            if (fadeData.ContainsKey(au))
            {
                data = fadeData[au];
            }
            else
            {
                if (catcheData.Count > 0)
                {
                    data = catcheData.Dequeue();
                }
                else
                {
                    data = new VolumeFadeData();
                }
                fadeData.Add(au, data);
                //data.tempVolume = 0;
                //Debug.Log("Add");
            }
            if (data.fadeOutCompleteCallBack != null)
            {
                data.fadeOutCompleteCallBack(data.au);
            }
            if (data.fadeCompleteCallBack != null)
            {
                data.fadeCompleteCallBack(data.au);
            }

            data.fadeCompleteCallBack    = null;
            data.fadeOutCompleteCallBack = null;
            data.au = au;
            if (flag != null)
            {
                au.flag = flag;
            }
            data.fadeType = fadeType;
            data.fadeTime = fadeTime;
            if (data.fadeTime <= 0)
            {
                data.fadeTime = 0.000001f;
            }
            data.fadeCompleteCallBack    = fadeCompleteCallBack;
            data.fadeOutCompleteCallBack = fadeOutCompleteCallBack;

            switch (data.fadeType)
            {
            case VolumeFadeType.FadeIn:
                data.au.Volume = 0;
                data.fadeState = VolumeFadeStateType.FadeIn;
                break;

            case VolumeFadeType.FadeOut:
                data.fadeState = VolumeFadeStateType.FadeOut;
                data.au.ResetVolume();
                break;

            case VolumeFadeType.FadeOut2In:
                data.fadeState = VolumeFadeStateType.FadeOut;
                data.au.ResetVolume();
                break;
            }
            data.tempVolume = data.au.Volume;
            data.delayTime  = delay;
            //Debug.Log("AddFade:"+ data.fadeType);
            //Debug.Log("Add  AddFade:" + JsonUtils.ToJson(data));
        }