(client) chore: 修改Clock继承自MonoSingleton

This commit is contained in:
m0_75251201
2025-07-09 17:27:14 +08:00
parent e0fd65071e
commit 4613f87573

View File

@ -25,49 +25,20 @@ namespace Base
}
}
public class Clock : MonoBehaviour
public class Clock : Ulity.MonoSingleton<Clock>
{
private static Clock _instance;
public bool pause;
public List<ITickPhysics> tickPhysics = new();
public List<ITick> ticks = new();
public List<ITickUI> tickUIs = new();
//float timer = 0;
public static Clock Instance
override protected void OnStart()
{
get
{
if (_instance == null)
{
// 检查场景中是否已存在实例
_instance = FindAnyObjectByType<Clock>();
// 注册场景加载事件
SceneManager.sceneLoaded += OnSceneLoaded;
// 如果不存在,创建一个新的
if (_instance == null)
{
var clockObject = new GameObject("[Clock]");
_instance = clockObject.AddComponent<Clock>();
DontDestroyOnLoad(clockObject); // 确保对象不被销毁
}
}
return _instance;
}
}
private void Awake()
{
// 确保只有一个实例存在
if (_instance != null && _instance != this)
{
Destroy(gameObject);
return;
}
_instance = this; // 设置当前实例为静态变量
SceneManager.sceneLoaded += OnSceneLoaded; // 注册场景加载事件
// 初始化时调用一次
Init();
}
private void Update()