Update ModuleSingle.cs

This commit is contained in:
MuHua-123
2025-01-20 11:14:27 +08:00
parent 7f4071505d
commit bf39077734
+11 -1
View File
@@ -14,8 +14,18 @@ public abstract class ModuleSingle<T> : MonoBehaviour where T : ModuleSingle<T>
/// <summary> 核心模块 </summary>
protected virtual ModuleCore ModuleCore => ModuleCore.I;
/// <summary> 初始化 </summary>
protected virtual void Awake() {
protected abstract void Awake();
/// <summary> 替换 </summary>
protected virtual void Replace(bool isDontDestroy = true) {
if (instance != null) { Destroy(instance.gameObject); }
instance = (T)this;
if (isDontDestroy) { DontDestroyOnLoad(gameObject); }
}
/// <summary> 不替换 </summary>
protected virtual void NoReplace(bool isDontDestroy = true) {
if (isDontDestroy) { DontDestroyOnLoad(gameObject); }
if (instance == null) { instance = (T)this; }
else { Destroy(gameObject); }
}
}