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

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.Collections;
using System.Collections.Generic;
@@ -12,29 +14,39 @@ namespace XericLibrary.Runtime.MacroLibrary
{
#region 名称文本
/// <summary>
/// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀
/// </summary>
[MethodImpl(MethodImplOptions.NoInlining)]
public static string GetGameObjectNameWithoutClone(GameObject gameObject)
{
return GetGameObjectNameWithoutClone(gameObject.name);
}
private readonly static string[] ignoresuffix= new string[]{
"(Clone)",
"(Instance)"
};
/// <summary>
/// 获取此处的物体名称,如果带有(clone)后缀,则省略这个后缀
/// </summary>
[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;
}
/// <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);
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