From bf390777342f248f72652ded5cd4dfcac95851c9 Mon Sep 17 00:00:00 2001 From: MuHua-123 <136542559+MuHua-123@users.noreply.github.com> Date: Mon, 20 Jan 2025 11:14:27 +0800 Subject: [PATCH] Update ModuleSingle.cs --- Assets/ModuleSingle/ModuleSingle.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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); } } }