添加了一种用于剔除的后缀

This commit is contained in:
2023-11-30 19:46:36 +08:00
parent cebe17be52
commit 39de0d24e3
2 changed files with 28 additions and 16 deletions
+27 -15
View File
@@ -1,3 +1,5 @@
using Sirenix.Utilities.Editor;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
@@ -12,29 +14,39 @@ namespace XericLibrary.Runtime.MacroLibrary
{ {
#region 名称文本 #region 名称文本
/// <summary> private readonly static string[] ignoresuffix= new string[]{
/// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀 "(Clone)",
/// </summary> "(Instance)"
[MethodImpl(MethodImplOptions.NoInlining)] };
public static string GetGameObjectNameWithoutClone(GameObject gameObject)
{
return GetGameObjectNameWithoutClone(gameObject.name);
}
/// <summary> /// <summary>
/// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀 /// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀
/// </summary> /// </summary>
[MethodImpl(MethodImplOptions.NoInlining)] [MethodImpl(MethodImplOptions.NoInlining)]
public static string GetGameObjectNameWithoutClone(string gameObjectName) [Obsolete("只忽略克隆后缀是过时的")]
public static string GetGameObjectNameWithoutClone(GameObject gameObject)
{ {
const string cloneSuffix = "(Clone)"; return gameObject.name;
if(gameObjectName.EndsWith(cloneSuffix)) }
/// <summary>
/// 获取一个对象名称,但忽略括号后缀
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.NoInlining)]
public static string GetUnityObjectRealName(this UnityEngine.Object obj)
{
for(int i = 0; i < ignoresuffix.Length; i++)
{ {
int suffixIndex = gameObjectName.LastIndexOf(cloneSuffix); if(obj.name.EndsWith(ignoresuffix[i]))
string nameWithoutClone = gameObjectName.Substring(0, suffixIndex); {
return nameWithoutClone; int suffixIndex = obj.name.LastIndexOf(ignoresuffix[i]);
string nameWithoutClone = obj.name.Substring(0, suffixIndex);
return nameWithoutClone;
}
} }
return gameObjectName; return obj.name;
} }
#endregion #endregion
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "com.lrss3.xericlibrary", "name": "com.lrss3.xericlibrary",
"displayName": "Xeric Library", "displayName": "Xeric Library",
"version": "0.2.414", "version": "0.2.415",
"unity": "2021.3", "unity": "2021.3",
"description": "\u901a\u7528\u5e93\u63d2\u4ef6\u3002" "description": "\u901a\u7528\u5e93\u63d2\u4ef6\u3002"
} }