| | |
| | | using UnityEngine; |
| | | |
| | | using System; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | public class SoundPlayer : MonoBehaviour |
| | | { |
| | |
| | | static readonly List<int> commonUseAudioSet = new List<int>() { defaultClickPositiveAudio, defaultClickNegativeAudio, 3, 4 }; |
| | | |
| | | static SoundPlayer m_Instance = null; |
| | | private static readonly object m_Lock = new object(); |
| | | public static SoundPlayer Instance |
| | | { |
| | | get |
| | | { |
| | | if (m_Instance == null) |
| | | { |
| | | CreateSoundPlayer(); |
| | | lock (m_Lock) |
| | | { |
| | | if (m_Instance == null) |
| | | { |
| | | CreateSoundPlayer(); |
| | | } |
| | | } |
| | | } |
| | | return m_Instance; |
| | | } |
| | | |
| | | } |
| | | |
| | | [SerializeField] AudioSource m_MusicAudioSource; |
| | |
| | | |
| | | Dictionary<int, AudioClip> commonUseAudioClipDict = new Dictionary<int, AudioClip>(); |
| | | Dictionary<int, AudioClip> musicAudioClipDict = new Dictionary<int, AudioClip>(); |
| | | |
| | | void Awake() |
| | | { |
| | | if (m_Instance == null) |
| | | { |
| | | m_Instance = this; |
| | | DontDestroyOnLoad(gameObject); |
| | | } |
| | | else if (m_Instance != this) |
| | | { |
| | | Destroy(gameObject); |
| | | } |
| | | } |
| | | |
| | | public event Action<bool> muteEvent; |
| | | bool m_Mute = false; |
| | |
| | | } |
| | | } |
| | | |
| | | public void Init() |
| | | { |
| | | //初始化用 |
| | | } |
| | | |
| | | public static void CreateSoundPlayer() |
| | | { |
| | | if (m_Instance != null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var gameObject = GameObject.Instantiate(BuiltInLoader.LoadPrefab("SoundPlayer")); |
| | | m_Instance = gameObject.GetComponent<SoundPlayer>(); |
| | | m_Instance.name = "SoundPlayer"; |
| | | m_Instance.SetActive(true); |
| | | DontDestroyOnLoad(gameObject); |
| | | Debug.Log("CreateSoundPlayer"); |
| | | } |
| | | |
| | | public void PlayBackGroundMusic(int _audioId) |
| | |
| | | StartCoroutine(Co_BackGroundMusicFadeOut()); |
| | | } |
| | | |
| | | public bool IsPlayBackGroundMuisic() |
| | | { |
| | | return m_MusicAudioSource.isPlaying; |
| | | } |
| | | |
| | | public void UnLoadMusic(int _exclude) |
| | | { |
| | | if (AssetSource.isUseAssetBundle && DeviceUtility.IsLowMemory()) |
| | |
| | | } |
| | | } |
| | | |
| | | //点击按钮播放特效的情况,点击音乐会覆盖特效音效,导致特效音效不播放,所以延迟播放 |
| | | public async UniTask PlayUIAudioDelay(int _audioId) |
| | | { |
| | | await UniTask.Delay(1); |
| | | PlayUIAudio(_audioId); |
| | | } |
| | | |
| | | public void PlayUIAudio(int _audioId) |
| | | { |
| | | if (_audioId <= 0) |