From dc96b23354556b5aad2e2b7ed8f3f546cc20890b Mon Sep 17 00:00:00 2001
From: LiRuoChen <571244399@qq.com>
Date: Thu, 26 Oct 2023 15:24:54 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=86=E5=8D=95=E4=BE=8B?=
=?UTF-8?q?=E7=B1=BB=E7=9A=84=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 14 +++++++-------
Runtime/Type/SingleMonoBase.cs | 25 +++++++++++++++++++------
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/README.md b/README.md
index 9434e9b..c2317e0 100644
--- a/README.md
+++ b/README.md
@@ -9,13 +9,13 @@
修改:事件扩展 InvokeConservative 从ExtendTypeç±»ä¸ç§»åˆ°äº†MacroEvent
* 0.1.1
- æ·»åŠ å¯¹è±¡å®�:组件查找,关系判æ–
- æ·»åŠ äº‹ä»¶å®�:事件调用
- æ·»åŠ æ•°å¦å®�:值循环与类型扩展
- æ·»åŠ æžšä¸¾å®�:枚举扩展
- æ·»åŠ å—符å®�:å—符功能扩展
- ç§»æ¤�弱类型:用于统一类型的判æ–,æ��供编å�·åŠŸèƒ½
- 移�特性�:�命�
+ æ·»åŠ å¯¹è±¡å®�:组件查找,关系判æ–
+ æ·»åŠ äº‹ä»¶å®�:事件调用
+ æ·»åŠ æ•°å¦å®�:值循环与类型扩展
+ æ·»åŠ æžšä¸¾å®�:枚举扩展
+ æ·»åŠ å—符å®�:å—符功能扩展
+ ç§»æ¤�弱类型:用于统一类型的判æ–,æ��供编å�·åŠŸèƒ½
+ 移�特性�:�命�
* 0.1.0
建立一些快æ�·çš„æ•°å¦å®�,数å¦ç®—法,数å¦å¸¸æ•°ï¼›
diff --git a/Runtime/Type/SingleMonoBase.cs b/Runtime/Type/SingleMonoBase.cs
index 4666fca..b577b82 100644
--- a/Runtime/Type/SingleMonoBase.cs
+++ b/Runtime/Type/SingleMonoBase.cs
@@ -6,14 +6,20 @@ using UnityEngine;
namespace XericLibrary.Runtime.Type
{
///
- /// µ¥Àý»ù´¡À࣬
+ /// µ¥Àý»ù´¡Àֻ࣬ÄÜ»ùÓÚMonoBehaviourÀà½øÐе¥ÀýÀ©Õ¹£»
+ /// Ö¸¶¨ÈÎºÎÆäËûµÄ·ºÐÍÀà¶¼»á¶ªÊ§ÆäÖеÄßÀ
///
///
- public class SingleMonoBase : MonoBehaviour
+ public class SingleMonoBase : MonoBehaviour
where T : Component
{
#region ×Ö¶ÎÊôÐÔ
+ ///
+ /// ¸ù½ÚµãÃû³Æ
+ ///
+ private static string rootNodeName = "DoNotDestroyThis";
+
///
/// ×é¼þµ¥Àý
///
@@ -52,7 +58,7 @@ namespace XericLibrary.Runtime.Type
inst = this as T;
if(inst == null)
- throw new System.Exception("µ¥Àý½Å±¾¸ø¶¨ÀàÐÍ´íÎó");
+ throw new System.Exception("µ¥ÀýÀàÐÍ´íÎ󣺵¥Àýϵͳ²»¿ÉÒÔÀ©Õ¹Ò»¸ö²¢·Ç×Ô¼ºµÄÀà");
}
#endregion
@@ -60,7 +66,7 @@ namespace XericLibrary.Runtime.Type
#region ·½·¨
///
- /// ÒÆ³ýÒ»¸öµ¥ÀýʵÀý
+ /// ÒÆ³ý´Ë´¦µÄµ¥ÀýʵÀý
///
protected bool DestroyInstance()
{
@@ -77,8 +83,15 @@ namespace XericLibrary.Runtime.Type
///
private static void InstanceLaunch()
{
- if (globalEmptyNode == null)
- globalEmptyNode = new GameObject("DoNotDestroyThis");
+ if(globalEmptyNode == null)
+ {
+#if UNITY_EDITOR
+ globalEmptyNode = GameObject.Find(rootNodeName);
+ if(globalEmptyNode == null)
+#endif
+ globalEmptyNode = new GameObject(rootNodeName);
+ }
+
globalEmptyNode.AddComponent();
}