Browse Source

Tools菜单增加ExcelExporter跟Proto2CS工具,mac上也能使用

tanghai 4 years ago
parent
commit
ac19759c7f

+ 114 - 0
Unity/Assets/Editor/Helper/ShellHelper.cs

@@ -0,0 +1,114 @@
+using System;
+using System.Diagnostics;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public static class ShellHelper
+    {
+        private static string shellApp
+        {
+            get
+            {
+#if UNITY_EDITOR_WIN
+			    string app = "cmd.exe";
+#elif UNITY_EDITOR_OSX
+                string app = "bash";
+#endif
+                return app;
+            }
+        }
+
+        public static void Run(string cmd, string workDirectory, List<string> environmentVars = null)
+        {
+            Process p = null;
+            try
+            {
+                ProcessStartInfo start = new ProcessStartInfo(shellApp);
+
+#if UNITY_EDITOR_OSX
+                string splitChar = ":";
+                start.Arguments = "-c";
+#elif UNITY_EDITOR_WIN
+                string splitChar = ";";
+				start.Arguments = "/c";
+#endif
+
+                if (environmentVars != null)
+                {
+                    foreach (string var in environmentVars)
+                    {
+                        start.EnvironmentVariables["PATH"] += (splitChar + var);
+                    }
+                }
+
+                start.Arguments += (" \"" + cmd + " \"");
+                start.CreateNoWindow = true;
+                start.ErrorDialog = true;
+                start.UseShellExecute = false;
+                start.WorkingDirectory = workDirectory;
+
+                if (start.UseShellExecute)
+                {
+                    start.RedirectStandardOutput = false;
+                    start.RedirectStandardError = false;
+                    start.RedirectStandardInput = false;
+                }
+                else
+                {
+                    start.RedirectStandardOutput = true;
+                    start.RedirectStandardError = true;
+                    start.RedirectStandardInput = true;
+                    start.StandardOutputEncoding = System.Text.Encoding.UTF8;
+                    start.StandardErrorEncoding = System.Text.Encoding.UTF8;
+                }
+
+                p = Process.Start(start);
+                p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { UnityEngine.Debug.LogError(e.Data); };
+                p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { UnityEngine.Debug.LogError(e.Data); };
+                p.Exited += delegate(object sender, System.EventArgs e) { UnityEngine.Debug.LogError(e.ToString()); };
+
+                bool hasError = false;
+                do
+                {
+                    string line = p.StandardOutput.ReadLine();
+                    if (line == null)
+                    {
+                        break;
+                    }
+
+                    line = line.Replace("\\", "/");
+
+                    UnityEngine.Debug.Log(line);
+                }
+                while (true);
+
+                while (true)
+                {
+                    string error = p.StandardError.ReadLine();
+                    if (string.IsNullOrEmpty(error))
+                    {
+                        break;
+                    }
+
+                    hasError = true;
+                    UnityEngine.Debug.LogError(error);
+                }
+
+                p.Close();
+                if (hasError)
+                {
+                    UnityEngine.Debug.LogError("has error!");
+                }
+            }
+            catch (Exception e)
+            {
+                UnityEngine.Debug.LogException(e);
+                if (p != null)
+                {
+                    p.Close();
+                }
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Editor/Helper/ShellHelper.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 61f2b8fe7ecd64cb3aad11c6a350638b
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 2
Unity/Assets/Editor/ReferenceCollectorEditor/ReferenceCollectorEditor.cs

@@ -7,8 +7,6 @@ using Object = UnityEngine.Object;
 
 //自定义ReferenceCollector类在界面中的显示与功能
 [CustomEditor(typeof (ReferenceCollector))]
-//没有该属性的编辑器在选中多个物体时会提示“Multi-object editing not supported”
-[CanEditMultipleObjects]
 public class ReferenceCollectorEditor: Editor
 {
     //输入在textfield中的字符串

+ 1 - 6
Unity/Assets/Editor/ServerCommandLineEditor/ServerCommandLineEditor.cs

@@ -1,9 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using UnityEditor;
+using UnityEditor;
 using UnityEngine;
 
 namespace ET

+ 8 - 0
Unity/Assets/Editor/ToolEditor.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c9f874225c3c8497c80a4cb6b07cd8df
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 29 - 0
Unity/Assets/Editor/ToolEditor/ToolsEditor.cs

@@ -0,0 +1,29 @@
+using UnityEditor;
+
+namespace ET
+{
+    public static class ToolsEditor
+    {
+        [MenuItem("Tools/ExcelExporter")]
+        public static void ExcelExporter()
+        {
+#if UNITY_EDITOR_OSX
+            const string tools = "./Tools";
+#else
+            const string tools = "./Tools.exe";
+#endif
+            ShellHelper.Run($"{tools} --AppType=ExcelExporter", "../Bin/");
+        }
+        
+        [MenuItem("Tools/Proto2CS")]
+        public static void Proto2CS()
+        {
+#if UNITY_EDITOR_OSX
+            const string tools = "./Tools";
+#else
+            const string tools = "./Tools.exe";
+#endif
+            ShellHelper.Run($"{tools} --AppType=Proto2CS", "../Bin/");
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Editor/ToolEditor/ToolsEditor.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 88c74536b8a114539ae8692d663b5c31
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: