EditorUtility.SaveFilePanel的应用

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);

            // 创建XML根标志

            XmlElement rootXmlElement = xmlDocument.CreateElement("root");

            //遍历所有的游戏对象

            foreach (UnityEngine.Object selectObject in selectedAssetList)

            {

                index++;

                string feilname = selectObject.name;

                // 创建文件标志

                XmlElement feilXmlElement = xmlDocument.CreateElement("tag");

                feilXmlElement.InnerText = feilname;

                rootXmlElement.AppendChild(feilXmlElement);

                xmlDocument.AppendChild(rootXmlElement);

            }

            // 保存文件数据

            xmlDocument.Save(path);

            // 刷新Project视图

            AssetDatabase.Refresh();

            EditorUtility.DisplayDialog("完成", "所有data文件已导入XML", "OK");

        }

    }


备注:SelectionModehttp://www.ceeger.com/Script/Editor_Enumerations/SelectionMode/SelectionMode.html

你可能感兴趣的:(EditorUtility.SaveFilePanel的应用)