Archived
添加了一种用于剔除的后缀
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user