Просмотр исходного кода

增加Mac平台运行及Tools工具适配 (#78)

增加Mac平台运行及Tools工具适配
LAC 7 лет назад
Родитель
Сommit
5f5b39188e

+ 1 - 0
Unity/Assets/Editor/BuildEditor/BuildEditor.cs

@@ -19,6 +19,7 @@ namespace ETEditor
 		Android,
 		IOS,
 		PC,
+		MacOS,
 	}
 	
 	public enum BuildType

+ 8 - 0
Unity/Assets/Editor/BuildEditor/BuildHelper.cs

@@ -35,6 +35,7 @@ namespace ETEditor
 		[MenuItem("Tools/web资源服务器")]
 		public static void OpenFileServer()
 		{
+#if !UNITY_EDITOR_OSX
 			string currentDir = System.Environment.CurrentDirectory;
 			string path = Path.Combine(currentDir, @"..\FileServer\");
 			System.Diagnostics.Process process = new System.Diagnostics.Process();
@@ -42,6 +43,10 @@ namespace ETEditor
 			process.StartInfo.WorkingDirectory = path;
 			process.StartInfo.CreateNoWindow = true;
 			process.Start();
+#else
+			string path = System.Environment.CurrentDirectory + "/../FileServer/";
+			("cd " + path + " && go run FileServer.go").Bash(path, true);
+#endif
 		}
 
 		public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB)
@@ -61,6 +66,9 @@ namespace ETEditor
 				case PlatformType.IOS:
 					buildTarget = BuildTarget.iOS;
 					break;
+				case PlatformType.MacOS:
+					buildTarget = BuildTarget.StandaloneOSX;
+					break;
 			}
 
 			string fold = string.Format(BuildFolder, type);

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

@@ -0,0 +1,42 @@
+using System.Diagnostics;
+using UnityEngine;
+
+namespace ETEditor {
+    public static class ShellHelper {
+        public static void Bash(this string cmd, string workingDirectory, bool startTerminal = false) {
+
+            ProcessStartInfo startInfo = new ProcessStartInfo("/bin/bash") {
+                    WorkingDirectory = workingDirectory,
+                    UseShellExecute = false,
+                    RedirectStandardInput = true,
+                    RedirectStandardOutput = true
+            };
+
+            Process process = new Process {
+                    StartInfo = startInfo
+            };
+
+            process.Start();
+            string code = "";
+            if(startTerminal) {
+                code = "osascript -e 'tell application \"Terminal\" to do script \"" +
+                       "" + cmd + "\" in selected tab of the front window'";
+            } else {
+                code = cmd;
+            }
+
+            process.StandardInput.WriteLine(code);
+            process.StandardInput.WriteLine("exit");
+            process.StandardInput.Flush();
+
+            string line = process.StandardOutput.ReadLine();
+
+            while(line != null) {
+                UnityEngine.Debug.Log("line:" + line);
+                line = process.StandardOutput.ReadLine();
+            }
+            process.WaitForExit();
+        }
+
+    }
+}

+ 4 - 1
Unity/Assets/Editor/Proto2CsEditor/Proto2CSEditor.cs

@@ -37,8 +37,11 @@ namespace ETEditor
 			msgOpcode.Clear();
 			Proto2CS("ETHotfix", "HotfixMessage.proto", hotfixMessagePath, "HotfixOpcode", 10000);
 
+#if !UNITY_EDITOR_OSX
 			CommandRun($"protoc.bat", "");
-
+#else
+			"bash ./protoc.sh".Bash(System.Environment.CurrentDirectory);
+#endif
 			AssetDatabase.Refresh();
 		}
 

+ 2 - 0
Unity/Assets/Scripts/Component/Config/GlobalProto.cs

@@ -14,6 +14,8 @@
 			url += "IOS/";
 #elif UNITY_WEBGL
 			url += "WebGL/";
+#elif UNITY_STANDALONE_OSX
+			url += "MacOS/";
 #else
 			url += "PC/";
 #endif

+ 6 - 0
Unity/protoc.sh

@@ -0,0 +1,6 @@
+#!/bin/bash
+
+protoc --csharp_out="./Assets/Scripts/Module/Message/" --proto_path="../Proto/" OuterMessage.proto
+protoc --csharp_out="./Hotfix/Module/Message/" --proto_path="../Proto/" HotfixMessage.proto
+echo finish
+