From 4613f87573bfa2e5df76955f027323ecea063c07 Mon Sep 17 00:00:00 2001 From: m0_75251201 Date: Wed, 9 Jul 2025 17:27:14 +0800 Subject: [PATCH] =?UTF-8?q?(client)=20chore:=20=E4=BF=AE=E6=94=B9Clock?= =?UTF-8?q?=E7=BB=A7=E6=89=BF=E8=87=AAMonoSingleton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Client/Assets/Scripts/Base/Clock.cs | 41 +++++------------------------ 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/Client/Assets/Scripts/Base/Clock.cs b/Client/Assets/Scripts/Base/Clock.cs index e51a0d8..c68b879 100644 --- a/Client/Assets/Scripts/Base/Clock.cs +++ b/Client/Assets/Scripts/Base/Clock.cs @@ -25,49 +25,20 @@ namespace Base } } - public class Clock : MonoBehaviour + public class Clock : Ulity.MonoSingleton { - private static Clock _instance; public bool pause; public List tickPhysics = new(); public List ticks = new(); public List tickUIs = new(); - //float timer = 0; - public static Clock Instance + override protected void OnStart() { - get - { - if (_instance == null) - { - // 检查场景中是否已存在实例 - _instance = FindAnyObjectByType(); + // 注册场景加载事件 + SceneManager.sceneLoaded += OnSceneLoaded; - // 如果不存在,创建一个新的 - if (_instance == null) - { - var clockObject = new GameObject("[Clock]"); - _instance = clockObject.AddComponent(); - DontDestroyOnLoad(clockObject); // 确保对象不被销毁 - } - } - - return _instance; - } - } - - - private void Awake() - { - // 确保只有一个实例存在 - if (_instance != null && _instance != this) - { - Destroy(gameObject); - return; - } - - _instance = this; // 设置当前实例为静态变量 - SceneManager.sceneLoaded += OnSceneLoaded; // 注册场景加载事件 + // 初始化时调用一次 + Init(); } private void Update()