From 39de0d24e3bed35bded2ba62471c68eb54d96e67 Mon Sep 17 00:00:00 2001 From: LiRuoChen <571244399@qq.com> Date: Thu, 30 Nov 2023 19:46:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E4=B8=80=E7=A7=8D?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E5=89=94=E9=99=A4=E7=9A=84=E5=90=8E=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/MicroLibrary/MacroString.cs | 42 ++++++++++++++++++----------- package.json | 2 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Runtime/MicroLibrary/MacroString.cs b/Runtime/MicroLibrary/MacroString.cs index 1eb52a2..5836fe4 100644 --- a/Runtime/MicroLibrary/MacroString.cs +++ b/Runtime/MicroLibrary/MacroString.cs @@ -1,3 +1,5 @@ +using Sirenix.Utilities.Editor; + using System; using System.Collections; using System.Collections.Generic; @@ -12,29 +14,39 @@ namespace XericLibrary.Runtime.MacroLibrary { #region 名称文本 - /// - /// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀 - /// - [MethodImpl(MethodImplOptions.NoInlining)] - public static string GetGameObjectNameWithoutClone(GameObject gameObject) - { - return GetGameObjectNameWithoutClone(gameObject.name); - } + private readonly static string[] ignoresuffix= new string[]{ + "(Clone)", + "(Instance)" + }; /// /// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀 /// [MethodImpl(MethodImplOptions.NoInlining)] - public static string GetGameObjectNameWithoutClone(string gameObjectName) + [Obsolete("只忽略克隆后缀是过时的")] + public static string GetGameObjectNameWithoutClone(GameObject gameObject) { - const string cloneSuffix = "(Clone)"; - if(gameObjectName.EndsWith(cloneSuffix)) + return gameObject.name; + } + + /// + /// 获取一个对象名称,但忽略括号后缀 + /// + /// + /// + [MethodImpl(MethodImplOptions.NoInlining)] + public static string GetUnityObjectRealName(this UnityEngine.Object obj) + { + for(int i = 0; i < ignoresuffix.Length; i++) { - int suffixIndex = gameObjectName.LastIndexOf(cloneSuffix); - string nameWithoutClone = gameObjectName.Substring(0, suffixIndex); - return nameWithoutClone; + if(obj.name.EndsWith(ignoresuffix[i])) + { + int suffixIndex = obj.name.LastIndexOf(ignoresuffix[i]); + string nameWithoutClone = obj.name.Substring(0, suffixIndex); + return nameWithoutClone; + } } - return gameObjectName; + return obj.name; } #endregion diff --git a/package.json b/package.json index 281b6f7..5933e0a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.lrss3.xericlibrary", "displayName": "Xeric Library", - "version": "0.2.414", + "version": "0.2.415", "unity": "2021.3", "description": "\u901a\u7528\u5e93\u63d2\u4ef6\u3002" } \ No newline at end of file