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

最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容