(client) chore: 修改Clock继承自MonoSingleton
This commit is contained in:
@ -25,49 +25,20 @@ namespace Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Clock : MonoBehaviour
|
public class Clock : Ulity.MonoSingleton<Clock>
|
||||||
{
|
{
|
||||||
private static Clock _instance;
|
|
||||||
public bool pause;
|
public bool pause;
|
||||||
public List<ITickPhysics> tickPhysics = new();
|
public List<ITickPhysics> tickPhysics = new();
|
||||||
public List<ITick> ticks = new();
|
public List<ITick> ticks = new();
|
||||||
public List<ITickUI> tickUIs = new();
|
public List<ITickUI> tickUIs = new();
|
||||||
|
|
||||||
//float timer = 0;
|
override protected void OnStart()
|
||||||
public static Clock Instance
|
|
||||||
{
|
{
|
||||||
get
|
// 注册场景加载事件
|
||||||
{
|
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||||
if (_instance == null)
|
|
||||||
{
|
|
||||||
// 检查场景中是否已存在实例
|
|
||||||
_instance = FindAnyObjectByType<Clock>();
|
|
||||||
|
|
||||||
// 如果不存在,创建一个新的
|
// 初始化时调用一次
|
||||||
if (_instance == null)
|
Init();
|
||||||
{
|
|
||||||
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; // 注册场景加载事件
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
Reference in New Issue
Block a user