Archived
调整了单例类的功能
This commit is contained in:
@@ -9,13 +9,13 @@
|
|||||||
修改:事件扩展 InvokeConservative 从ExtendType类中移到了MacroEvent
|
修改:事件扩展 InvokeConservative 从ExtendType类中移到了MacroEvent
|
||||||
|
|
||||||
* 0.1.1
|
* 0.1.1
|
||||||
添加对象宏:组件查找,关系判断
|
添加对象宏:组件查找,关系判断
|
||||||
添加事件宏:事件调用
|
添加事件宏:事件调用
|
||||||
添加数学宏:值循环与类型扩展
|
添加数学宏:值循环与类型扩展
|
||||||
添加枚举宏:枚举扩展
|
添加枚举宏:枚举扩展
|
||||||
添加字符宏:字符功能扩展
|
添加字符宏:字符功能扩展
|
||||||
移植弱类型:用于统一类型的判断,提供编号功能
|
移植弱类型:用于统一类型的判断,提供编号功能
|
||||||
移植特性宏:重命名
|
移植特性宏:重命名
|
||||||
|
|
||||||
* 0.1.0
|
* 0.1.0
|
||||||
建立一些快捷的数学宏,数学算法,数学常数;
|
建立一些快捷的数学宏,数学算法,数学常数;
|
||||||
|
|||||||
@@ -6,14 +6,20 @@ using UnityEngine;
|
|||||||
namespace XericLibrary.Runtime.Type
|
namespace XericLibrary.Runtime.Type
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 单例基础类,
|
/// 单例基础类,只能基于MonoBehaviour类进行单例扩展;
|
||||||
|
/// 指定任何其他的泛型类都会丢失其中的呃
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class SingleMonoBase<T> : MonoBehaviour
|
public class SingleMonoBase<T> : MonoBehaviour
|
||||||
where T : Component
|
where T : Component
|
||||||
{
|
{
|
||||||
#region 字段属性
|
#region 字段属性
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 根节点名称
|
||||||
|
/// </summary>
|
||||||
|
private static string rootNodeName = "DoNotDestroyThis";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 组件单例
|
/// 组件单例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,7 +58,7 @@ namespace XericLibrary.Runtime.Type
|
|||||||
|
|
||||||
inst = this as T;
|
inst = this as T;
|
||||||
if(inst == null)
|
if(inst == null)
|
||||||
throw new System.Exception("单例脚本给定类型错误");
|
throw new System.Exception("单例类型错误:单例系统不可以扩展一个并非自己的类");
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@@ -60,7 +66,7 @@ namespace XericLibrary.Runtime.Type
|
|||||||
#region 方法
|
#region 方法
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 移除一个单例实例
|
/// 移除此处的单例实例
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool DestroyInstance()
|
protected bool DestroyInstance()
|
||||||
{
|
{
|
||||||
@@ -77,8 +83,15 @@ namespace XericLibrary.Runtime.Type
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static void InstanceLaunch()
|
private static void InstanceLaunch()
|
||||||
{
|
{
|
||||||
if (globalEmptyNode == null)
|
if(globalEmptyNode == null)
|
||||||
globalEmptyNode = new GameObject("DoNotDestroyThis");
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
globalEmptyNode = GameObject.Find(rootNodeName);
|
||||||
|
if(globalEmptyNode == null)
|
||||||
|
#endif
|
||||||
|
globalEmptyNode = new GameObject(rootNodeName);
|
||||||
|
}
|
||||||
|
|
||||||
globalEmptyNode.AddComponent<T>();
|
globalEmptyNode.AddComponent<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user