using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// 单例模块 /// public abstract class ModuleSingle : MonoBehaviour where T : ModuleSingle { /// 模块单例 public static T I => instance; /// 模块单例 protected static T instance; /// 核心模块 protected virtual ModuleCore ModuleCore => ModuleCore.I; /// 初始化 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); } } }