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;
}
网友评论