Esempio n. 1
0
    /// <summary>
    /// 播放背景音效 (按名称,次数,音量)
    /// </summary>
    public void PlayBGM(string kBGM, int playCount = 0)
    {
        if (string.IsNullOrEmpty(kBGM))
        {
            return;
        }
        AudioSource component = myBgmSource;

        component.loop = true;

        string audioBundlePath = SoundLoader.GetAudioAssetPath(kBGM);

        BGMLoader bGMLoader = new BGMLoader();

        bGMLoader.kBGM  = component;
        bGMLoader.kName = kBGM;
        bGMLoader.fVol  = Mathf.Clamp01(GameCenter.systemSettingMng.BGMVolume);
        if (playCount == 0)
        {
            bGMLoader.playCount  = 0;
            bGMLoader.OnPlayTime = null;
        }
        else
        {
            bGMLoader.playCount  = playCount;
            bGMLoader.OnPlayTime = CancelInserBGNDelay;
        }
        mySoundLoader.RequestAsyncLoad(audioBundlePath, kBGM, bGMLoader);
    }
Esempio n. 2
0
 /// <summary>
 /// 清除缓存
 /// </summary>
 public void ClearCache()
 {
     foreach (var item in this.mySoundClipCache)
     {
         string audioBundlePath = SoundLoader.GetAudioAssetPath(item.Key);
         UnloadAsset(audioBundlePath);
         if (item.Value != null)
         {
             GameObject.Destroy(item.Value);
         }
         cullingActive = false;
     }
     this.mySoundClipCache.Clear();
 }
Esempio n. 3
0
    /// <summary>
    /// 添加到缓存
    /// </summary>
    public void AddCache(string _soundName)
    {
        if (_soundName == "0" || _soundName == string.Empty)
        {
            return;
        }
        if (this.mySoundClipCache.ContainsKey(_soundName))
        {
            if (this.mySoundClipCache[_soundName] == null)
            {
                mySoundClipCache.Remove(_soundName);
            }
            else
            {
                return;
            }
        }
        AudioLoader audioLoader     = new AudioLoader();
        string      audioBundlePath = SoundLoader.GetAudioAssetPath(_soundName);

        audioLoader.kName = _soundName;
        RequestAsyncLoad(audioBundlePath, _soundName, audioLoader);
    }