Unity編輯器之導入導出獲取路徑對話框
[MenuItem("ExportXmlLanguage/導出xml作為參照文本")]
? ? static void ExportXML()
? ? {
? ? ? ? string path = EditorUtility.SaveFilePanel("Save Resource", "", "RootDataLanguage", "xml");
? ? ? ? if (path.Length != 0)
? ? ? ? {
? ? ? ? ? ? UnityEngine.Object[] selectedAssetList = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);
? ? ? ? ? ? string[] files = Directory.GetFiles(endtargetpath);
? ? ? ? ? ? int index = 0;
? ? ? ? ? ? XmlDocument xmlDocument = new XmlDocument();
? ? ? ? ? ? XmlDeclaration xmlDeclaration = xmlDocument.CreateXmlDeclaration("1.0", "utf-8", null);
? ? ? ? ? ? xmlDocument.AppendChild(xmlDeclaration);
? ? ? ? ? ? // 創(chuàng)建XML根標志
? ? ? ? ? ? XmlElement rootXmlElement = xmlDocument.CreateElement("root");
? ? ? ? ? ? //遍歷所有的游戲?qū)ο?/p>
? ? ? ? ? ? foreach (UnityEngine.Object selectObject in selectedAssetList)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? index++;
? ? ? ? ? ? ? ? string feilname = selectObject.name;
? ? ? ? ? ? ? ? // 創(chuàng)建文件標志
? ? ? ? ? ? ? ? XmlElement feilXmlElement = xmlDocument.CreateElement("tag");
? ? ? ? ? ? ? ? feilXmlElement.InnerText = feilname;
? ? ? ? ? ? ? ? rootXmlElement.AppendChild(feilXmlElement);
? ? ? ? ? ? ? ? xmlDocument.AppendChild(rootXmlElement);
? ? ? ? ? ? }
? ? ? ? ? ? // 保存文件數(shù)據(jù)
? ? ? ? ? ? xmlDocument.Save(path);
? ? ? ? ? ? // 刷新Project視圖
? ? ? ? ? ? AssetDatabase.Refresh();
? ? ? ? ? ? EditorUtility.DisplayDialog("完成", "所有data文件已導入XML", "OK");
? ? ? ? }
? ? }
備注:SelectionModehttp://www.ceeger.com/Script/Editor_Enumerations/SelectionMode/SelectionMode.html
