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()