美文网首页
unity代码添加Tag

unity代码添加Tag

作者: 红定义 | 来源:发表于2017-03-07 08:22 被阅读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;

    }

    相关文章

      网友评论

          本文标题:unity代码添加Tag

          本文链接:https://www.haomeiwen.com/subject/cgmpgttx.html