From 89343a7a0909e5244a3b69c4db1294de4536243b Mon Sep 17 00:00:00 2001
From: lcy <1459594991@qq.com>
Date: 星期一, 15 十二月 2025 18:15:22 +0800
Subject: [PATCH] 262 幻境阁系统-客户端 新增仅适用武将解锁的头像和形象的红点移除规则

---
 Main/System/Sound/SoundPlayer.cs |   89 +++++++++++++++++++++++++++++++++++---------
 1 files changed, 71 insertions(+), 18 deletions(-)

diff --git a/Main/System/Sound/SoundPlayer.cs b/Main/System/Sound/SoundPlayer.cs
index 3315f86..d8c553f 100644
--- a/Main/System/Sound/SoundPlayer.cs
+++ b/Main/System/Sound/SoundPlayer.cs
@@ -3,6 +3,7 @@
 using UnityEngine;
 
 using System;
+using Cysharp.Threading.Tasks;
 
 public class SoundPlayer : MonoBehaviour
 {
@@ -11,8 +12,24 @@
 
     static readonly List<int> commonUseAudioSet = new List<int>() { defaultClickPositiveAudio, defaultClickNegativeAudio, 3, 4 };
 
-    public static SoundPlayer Instance {
-        get; set;
+    static SoundPlayer m_Instance = null;
+    private static readonly object m_Lock = new object();
+    public static SoundPlayer Instance
+    {
+        get
+        {
+            if (m_Instance == null)
+            {
+                lock (m_Lock)
+                {
+                    if (m_Instance == null)
+                    {
+                        CreateSoundPlayer();
+                    }
+                }
+            }
+            return m_Instance;
+        }
     }
 
     [SerializeField] AudioSource m_MusicAudioSource;
@@ -24,6 +41,19 @@
 
     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;
@@ -42,13 +72,24 @@
         }
     }
 
+    public void Init()
+    {
+        //鍒濆鍖栫敤
+    }
+
     public static void CreateSoundPlayer()
     {
+        if (m_Instance != null)
+        {
+            return;
+        }
+
         var gameObject = GameObject.Instantiate(BuiltInLoader.LoadPrefab("SoundPlayer"));
-        Instance = gameObject.GetComponent<SoundPlayer>();
-        Instance.name = "SoundPlayer";
-        Instance.SetActive(true);
+        m_Instance = gameObject.GetComponent<SoundPlayer>();
+        m_Instance.name = "SoundPlayer";
+        m_Instance.SetActive(true);
         DontDestroyOnLoad(gameObject);
+        Debug.Log("CreateSoundPlayer");
     }
 
     public void PlayBackGroundMusic(int _audioId)
@@ -122,6 +163,11 @@
         StartCoroutine(Co_BackGroundMusicFadeOut());
     }
 
+    public bool IsPlayBackGroundMuisic()
+    {
+        return m_MusicAudioSource.isPlaying;
+    }
+
     public void UnLoadMusic(int _exclude)
     {
         if (AssetSource.isUseAssetBundle && DeviceUtility.IsLowMemory())
@@ -144,6 +190,13 @@
                 }
             }
         }
+    }
+
+    //鐐瑰嚮鎸夐挳鎾斁鐗规晥鐨勬儏鍐碉紝鐐瑰嚮闊充箰浼氳鐩栫壒鏁堥煶鏁堬紝瀵艰嚧鐗规晥闊虫晥涓嶆挱鏀撅紝鎵�浠ュ欢杩熸挱鏀�
+    public async UniTask PlayUIAudioDelay(int _audioId)
+    {
+        await UniTask.Delay(1);
+        PlayUIAudio(_audioId);
     }
 
     public void PlayUIAudio(int _audioId)
@@ -302,21 +355,21 @@
         }
     }
 
-    //public void PlayLoginMusic()
-    //{
-    //    var loginMusic = BuiltInLoader.LoadMusic("Music_Login");
-    //    if (!m_MusicAudioSource.isPlaying || m_MusicAudioSource.clip != loginMusic)
-    //    {
-    //        StartCoroutine(Co_BackGroundMusicFadeOutIn(loginMusic, false));
-    //    }
-    //}
+    public void PlayLoginMusic()
+    {
+       var loginMusic = BuiltInLoader.LoadMusic("login");
+       if (!m_MusicAudioSource.isPlaying || m_MusicAudioSource.clip != loginMusic)
+       {
+           StartCoroutine(Co_BackGroundMusicFadeOutIn(loginMusic, false));
+       }
+    }
 
     //private void LateUpdate()
-    //{
-    //    if (CameraController.Instance != null && CameraController.Instance.CameraObject != null)
-    //    {
-    //        this.transform.position = CameraController.Instance.transform.position + new Vector3(0, 5, 0);
-    //        this.transform.rotation = CameraController.Instance.CameraObject.transform.rotation;
+    //{
+    //    if (CameraController.Instance != null && CameraController.Instance.CameraObject != null)
+    //    {
+    //        this.transform.position = CameraController.Instance.transform.position + new Vector3(0, 5, 0);
+    //        this.transform.rotation = CameraController.Instance.CameraObject.transform.rotation;
     //    }
     //}
 

--
Gitblit v1.8.0