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;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 背景 一年多以前我在知乎上答了有關(guān)LeetCode的問題, 分享了一些自己做題目的經(jīng)驗。 張土汪:刷leetcod...
    土汪閱讀 12,916評論 0 33
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評論 19 139
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,687評論 18 399
  • Correctness AdapterViewChildren Summary: AdapterViews can...
    MarcusMa閱讀 9,053評論 0 6
  • Java經(jīng)典問題算法大全 /*【程序1】 題目:古典問題:有一對兔子,從出生后第3個月起每個月都生一對兔子,小兔子...
    趙宇_阿特奇閱讀 2,075評論 0 2

友情鏈接更多精彩內(nèi)容