增加了基础工具包
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 单例基类
|
||||
/// </summary>
|
||||
public class Single<T> where T : Single<T>, new() {
|
||||
/// <summary> 模块单例 </summary>
|
||||
public static T I => Instantiate();
|
||||
|
||||
protected static T instance;
|
||||
protected static T Instantiate() => instance == null ? instance = new T() : instance;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 864d5767e91be034eb47a0561aba685a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 单例行为
|
||||
/// </summary>
|
||||
public abstract class SingleBehaviour<T> : MonoBehaviour where T : SingleBehaviour<T> {
|
||||
/// <summary> 模块单例 </summary>
|
||||
public static T I => instance;
|
||||
/// <summary> 模块单例 </summary>
|
||||
protected static T instance;
|
||||
/// <summary> 初始化 </summary>
|
||||
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); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 103d1480bcf841b40858282d95c83e99
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user