using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; //声音的控制 public class GameSoundManager{ private static GameSoundManager _instance; //环境音乐是多个的时候 就要写一个List了 private AudioSource bgSound; //所有的非预制件的音效的 private List effectSoundList; //所有的非预制件的音效的 private List environmentSoundList; public static GameSoundManager Instance { get { if (_instance == null) { _instance = new GameSoundManager (); } return _instance; } } private GameSoundManager() { effectSoundList = new List(); environmentSoundList = new List (); } public void Init() { } public void RefreshBgSound() { foreach(AudioSource source in environmentSoundList) { RefreshBGSource (source); } } public void RefreshEffectSound() { foreach(AudioSource source in effectSoundList) { RefreshSource (source); } } private void RefreshSource(AudioSource source) { if (GameDataSetting.Instance.EffectSoundSwitch) { source.volume = GameDataSetting.Instance.EffectSoundValue;//音量大小 } else { source.volume = 0; } } private void RefreshBGSource(AudioSource source) { if (GameDataSetting.Instance.BGSoundSwitch) { source.volume = GameDataSetting.Instance.BgSoundValue;//音量大小 } else { source.volume = 0; } } //缓解音乐注册 public void RegisterBG(AudioSource source, GameObject obj) { if (!environmentSoundList.Contains(source)) { environmentSoundList.Add(source); } RefreshBGSource (source); } //环境音乐注销 public void UnRegisterBG(AudioSource source) { if (environmentSoundList.Contains(source)) { environmentSoundList.Remove(source); } } //音效注册 public void Register(AudioSource source, GameObject obj) { if (!effectSoundList.Contains(source)) { effectSoundList.Add(source); } RefreshSource (source); } //音效注销 public void UnRegister(AudioSource source) { if (effectSoundList.Contains(source)) { effectSoundList.Remove(source); } } }