unity代码添加Tag

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;

}

你可能感兴趣的:(unity代码添加Tag)