123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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<AudioSource> effectSoundList;
- //所有的非预制件的音效的
- private List<AudioSource> environmentSoundList;
- public static GameSoundManager Instance
- {
- get
- {
- if (_instance == null) {
- _instance = new GameSoundManager ();
- }
- return _instance;
- }
- }
- private GameSoundManager()
- {
- effectSoundList = new List<AudioSource>();
- environmentSoundList = new List<AudioSource> ();
- }
- 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);
- }
- }
- }
|