using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MuHua {
///
/// 单例行为
///
public abstract class SingleBehaviour : MonoBehaviour where T : SingleBehaviour {
/// 模块单例
public static T I => instance;
/// 模块单例
protected static T instance;
/// 初始化
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); }
}
}
}