예제 #1
0
        /// <summary>
        /// 播放音效
        /// </summary>
        /// <param name="name">资源名称</param>
        public void PlaySound(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            // 如果静音状态直接跳过播放
            if (IsMute(EAudioLayer.Sound))
            {
                return;
            }

            if (_assets.ContainsKey(name))
            {
                if (_assets[name].Result == EAssetResult.OK)
                {
                    PlayAudioClipInternal(EAudioLayer.Sound, _assets[name].Clip, false);
                }
            }
            else
            {
                // 新建加载资源
                AssetAudio assetAudio = new AssetAudio((int)EAudioLayer.Sound);
                _assets.Add(name, assetAudio);
                assetAudio.Load(BaseFolderPath + name, (Asset asset) =>
                {
                    if (asset.Result == EAssetResult.OK)
                    {
                        PlayAudioClipInternal(EAudioLayer.Sound, _assets[name].Clip, false);
                    }
                });
            }
        }
예제 #2
0
        /// <summary>
        /// 播放环境音效
        /// </summary>
        /// <param name="name">资源名称</param>
        /// <param name="loop">是否循环播放</param>
        public void PlayAmbient(string name, bool loop)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (_assets.ContainsKey(name))
            {
                if (_assets[name].Result == EAssetResult.OK)
                {
                    PlayAudioClipInternal(EAudioLayer.Ambient, _assets[name].Clip, loop);
                }
            }
            else
            {
                // 新建加载资源
                AssetAudio assetAudio = new AssetAudio((int)EAudioLayer.Ambient);
                _assets.Add(name, assetAudio);
                assetAudio.Load(BaseFolderPath + name, (Asset asset) =>
                {
                    if (asset.Result == EAssetResult.OK)
                    {
                        PlayAudioClipInternal(EAudioLayer.Ambient, _assets[name].Clip, loop);
                    }
                });
            }
        }
예제 #3
0
        /// <summary>
        /// 播放背景音乐
        /// </summary>
        /// <param name="name">资源名称</param>
        /// <param name="loop">是否循环播放</param>
        public void PlayMusic(string name, bool loop)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            if (_assets.ContainsKey(name))
            {
                if (_assets[name].Result == EAssetResult.OK)
                {
                    PlayAudioClipInternal(EAudioLayer.Music, _assets[name].Clip, loop);
                    PlayFadeEffect(EFadeMode.FadeIn);
                }
            }
            else
            {
                // 新建加载资源
                AssetAudio assetAudio = new AssetAudio((int)EAudioLayer.Music);
                _assets.Add(name, assetAudio);
                assetAudio.Load(BaseFolderPath + name, (Asset asset, EAssetResult result) =>
                {
                    if (result == EAssetResult.OK)
                    {
                        PlayAudioClipInternal(EAudioLayer.Music, _assets[name].Clip, loop);
                        PlayFadeEffect(EFadeMode.FadeIn);
                    }
                });
            }
        }
예제 #4
0
 /// <summary>
 /// 预加载音频资源
 /// </summary>
 public void PreloadAsset(string name, int audioType)
 {
     if (_assets.ContainsKey(name) == false)
     {
         AssetAudio asset = new AssetAudio(audioType);
         _assets.Add(name, asset);
         asset.Load(BaseFolderPath + name, null);
     }
 }
예제 #5
0
        /// <summary>
        /// 使用外部音频源播放音效
        /// </summary>
        /// <param name="audio">外部的音频源</param>
        /// <param name="name">资源名称</param>
        public void PlaySound(AudioSource audio, string name)
        {
            if (audio == null)
            {
                return;
            }
            if (audio.isActiveAndEnabled == false)
            {
                return;
            }
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            // 如果静音状态直接跳过播放
            if (IsMute(EAudioLayer.Sound))
            {
                return;
            }

            if (_assets.ContainsKey(name))
            {
                if (_assets[name].Result == EAssetResult.OK)
                {
                    if (audio != null)
                    {
                        audio.PlayOneShot(_assets[name].Clip);
                    }
                }
            }
            else
            {
                // 新建加载资源
                AssetAudio assetAudio = new AssetAudio((int)EAudioLayer.Sound);
                _assets.Add(name, assetAudio);
                assetAudio.Load(BaseFolderPath + name, (Asset asset) =>
                {
                    if (asset.Result == EAssetResult.OK)
                    {
                        if (audio != null)
                        {
                            audio.PlayOneShot(_assets[name].Clip);
                        }
                    }
                });
            }
        }