From 7b543e40975a787f8b1b4fe1cd6fb075cf95f458 Mon Sep 17 00:00:00 2001 From: tanghai Date: Thu, 27 Oct 2016 17:27:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=BD=E4=BB=A4=E8=A1=8C=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E5=8F=AF=E4=BB=A5=20=E6=B7=BB=E5=8A=A0=20=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=20=E9=87=8D=E5=91=BD=E5=90=8D=20=E5=88=A0=E9=99=A4=20?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ServerCommandLineEditor.cs | 69 +++++++++++++++---- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs b/Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs index b74629c4..3ca2a87f 100644 --- a/Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs +++ b/Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs @@ -20,7 +20,7 @@ namespace MyEditor private string fileName; - private string addFileName; + private string newFileName = ""; private int copyNum = 1; @@ -89,6 +89,19 @@ namespace MyEditor return Path.Combine(ConfigDir, this.fileName); } + private void Save() + { + string path = this.GetFilePath(); + using (StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Create))) + { + foreach (StartConfig startConfig in this.startConfigs) + { + sw.Write(MongoHelper.ToJson(startConfig)); + sw.Write('\n'); + } + } + } + private void OnGUI() { GUILayout.BeginHorizontal(); @@ -103,16 +116,52 @@ namespace MyEditor this.LoadConfig(); } - this.addFileName = EditorGUILayout.TextField("文件名", this.addFileName); + this.newFileName = EditorGUILayout.TextField("文件名", this.newFileName); - if (GUILayout.Button("添加配置文件")) + if (GUILayout.Button("添加")) { - this.fileName = this.addFileName; - this.addFileName = ""; + this.fileName = this.newFileName; + this.newFileName = ""; File.WriteAllText(this.GetFilePath(), ""); this.files = this.GetConfigFiles(); this.selectedIndex = this.files.IndexOf(this.fileName); + this.LoadConfig(); } + + if (GUILayout.Button("复制")) + { + this.fileName = $"{this.fileName}-copy"; + this.Save(); + this.files = this.GetConfigFiles(); + this.selectedIndex = this.files.IndexOf(this.fileName); + this.newFileName = ""; + } + + if (GUILayout.Button("重命名")) + { + if (this.newFileName == "") + { + Log.Debug("请输入新名字!"); + } + else + { + File.Delete(this.GetFilePath()); + this.fileName = this.newFileName; + this.Save(); + this.files = this.GetConfigFiles(); + this.selectedIndex = this.files.IndexOf(this.fileName); + this.newFileName = ""; + } + } + + if (GUILayout.Button("删除")) + { + File.Delete(this.GetFilePath()); + this.files = this.GetConfigFiles(); + this.selectedIndex = 0; + this.newFileName = ""; + } + GUILayout.EndHorizontal(); GUILayout.Label("配置内容:"); @@ -193,15 +242,7 @@ namespace MyEditor if (GUILayout.Button("保存")) { - string path = this.GetFilePath(); - using (StreamWriter sw = new StreamWriter(new FileStream(path, FileMode.Create))) - { - foreach (StartConfig startConfig in this.startConfigs) - { - sw.Write(MongoHelper.ToJson(startConfig)); - sw.Write('\n'); - } - } + this.Save(); } if (GUILayout.Button("启动")) -- GitLab