diff --git a/Assets/ModuleSingle/ModuleSingle.cs b/Assets/ModuleSingle/ModuleSingle.cs index 028f176..5457c05 100644 --- a/Assets/ModuleSingle/ModuleSingle.cs +++ b/Assets/ModuleSingle/ModuleSingle.cs @@ -14,8 +14,18 @@ public abstract class ModuleSingle : MonoBehaviour where T : ModuleSingle /// 核心模块 protected virtual ModuleCore ModuleCore => ModuleCore.I; /// 初始化 - protected virtual void Awake() { + protected abstract void Awake(); + + /// 替换 + protected virtual void Replace(bool isDontDestroy = true) { if (instance != null) { Destroy(instance.gameObject); } instance = (T)this; + if (isDontDestroy) { DontDestroyOnLoad(gameObject); } + } + /// 不替换 + protected virtual void NoReplace(bool isDontDestroy = true) { + if (isDontDestroy) { DontDestroyOnLoad(gameObject); } + if (instance == null) { instance = (T)this; } + else { Destroy(gameObject); } } }