Browse Source

增加编辑器导出数据给unity时,记忆上一次选择路径的功能

大爷 1 year ago
parent
commit
8a5434bd3f
1 changed files with 41 additions and 7 deletions
  1. 41 7
      GameEditor/Editor.cs

+ 41 - 7
GameEditor/Editor.cs

@@ -1506,16 +1506,50 @@ namespace CommonAIEditor
             Process p = Process.Start("ResBuilder.exe");
             p.WaitForExit();
 
-            string sPath = "";
-            FolderBrowserDialog folder = new FolderBrowserDialog();
-            folder.Description = "选择文件所在文件夹目录";  //定义在对话框上显示的文本
-            if (folder.ShowDialog() == DialogResult.OK)
+            string sPath = null;
+
+            string tmpCfg = "./lastSave.cfg";
+            if (File.Exists(tmpCfg)) 
             {
-                sPath = folder.SelectedPath;
+                try
+                {
+                    FileStream fs = new FileStream(tmpCfg, FileMode.Open, FileAccess.Read);
+                    byte[] bytes = new byte[256];
+                    int len = fs.Read(bytes, 0, bytes.Length - 1);
+                    if (len > 0)
+                    {
+                        sPath = System.Text.Encoding.UTF8.GetString(bytes, 0, len);
+                        if (!Directory.Exists(sPath))
+                        {
+                            sPath = null;
+                        }
+                    }
+                    fs.Close();
+                }
+                catch (Exception) { }
             }
-            else
+
+            if (sPath == null)
             {
-                return;
+                FolderBrowserDialog folder = new FolderBrowserDialog();
+                folder.Description = "选择文件所在文件夹目录";  //定义在对话框上显示的文本
+                if (folder.ShowDialog() == DialogResult.OK)
+                {
+                    sPath = folder.SelectedPath;
+
+                    try
+                    {
+                        FileStream fs = new FileStream(tmpCfg, FileMode.OpenOrCreate, FileAccess.ReadWrite);
+                        byte[] bytes = System.Text.Encoding.UTF8.GetBytes(sPath);
+                        fs.Write(bytes, 0, bytes.Length);
+                        fs.Close();
+                    } 
+                    catch (Exception) { }
+                }
+                else
+                {
+                    return;
+                }
             }