unity代码添加Tag

2017-03-07  本文已影响0人  红定义

static void AddTag(string tag)

{

if (!isHasTag(tag))

{

SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);

SerializedProperty it = tagManager.GetIterator();

while (it.NextVisible(true))

{

if (it.name == "tags")

{

int count = it.arraySize;

it.InsertArrayElementAtIndex(count);

SerializedProperty dataPoint = it.GetArrayElementAtIndex(count);

dataPoint.stringValue = tag;

tagManager.ApplyModifiedProperties();

return;

}

}

}

}

static bool isHasTag(string tag)

{

for (int i = 0; i < UnityEditorInternal.InternalEditorUtility.tags.Length; i++)

{

if (UnityEditorInternal.InternalEditorUtility.tags[i].Equals(tag))

return true;

}

return false;

}

上一篇下一篇

猜你喜欢

热点阅读