解决Mac执行Mono的EXE的问题

因为我们之前都没有考虑到Mac的打包,打包流程都在windows下走的,所有没有考虑到mac下的兼容性问题,今天打mac包发现有部分功能失效了,仔细看发现报了一个Win32的错,如下:

"/Volumes/UnityForGame/Game/Client/Assets/Scripts/Game Logic" "/Volumes/UnityForGame/Game/Client/Assets/Scripts/XLua"', CurrentDirectory=''
System.Diagnostics.Process.Start_noshell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process)
System.Diagnostics.Process.Start ()
(wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()

mac下执行mono exe的方式和windows下是不同的,windows下直接走下面这段代码就可以了

            System.Diagnostics.Process hotfix_injection = new System.Diagnostics.Process();
            hotfix_injection.StartInfo.FileName = "xx.exe";
            hotfix_injection.StartInfo.Arguments = "args";
            hotfix_injection.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            hotfix_injection.StartInfo.RedirectStandardOutput = true;
            hotfix_injection.StartInfo.UseShellExecute = false;
            hotfix_injection.StartInfo.CreateNoWindow = true;
            hotfix_injection.Start();
            hotfix_injection.WaitForExit();
            UnityEngine.Debug.Log(hotfix_injection.StandardOutput.ReadToEnd());

而Mac下要修改为

            System.Diagnostics.Process hotfix_injection = new System.Diagnostics.Process();
            hotfix_injection.StartInfo.FileName = "mono_path";
            hotfix_injection.StartInfo.Arguments = "xx.exe args";
            hotfix_injection.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            hotfix_injection.StartInfo.RedirectStandardOutput = true;
            hotfix_injection.StartInfo.UseShellExecute = false;
            hotfix_injection.StartInfo.CreateNoWindow = true;
            hotfix_injection.Start();
            hotfix_injection.WaitForExit();
            UnityEngine.Debug.Log(hotfix_injection.StandardOutput.ReadToEnd());

其中mono_path需要通过在终端输入which mono来查询到


最终的代码如下:

            System.Diagnostics.Process hotfix_injection = new System.Diagnostics.Process();
#if UNITY_IOS
            hotfix_injection.StartInfo.FileName = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/mono";
            hotfix_injection.StartInfo.Arguments = "xx.exe args";
#else
            hotfix_injection.StartInfo.FileName = "xx.exe";
            hotfix_injection.StartInfo.Arguments = "args";
#endif
            hotfix_injection.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            hotfix_injection.StartInfo.RedirectStandardOutput = true;
            hotfix_injection.StartInfo.UseShellExecute = false;
            hotfix_injection.StartInfo.CreateNoWindow = true;
            hotfix_injection.Start();
            hotfix_injection.WaitForExit();
            UnityEngine.Debug.Log(hotfix_injection.StandardOutput.ReadToEnd());

你可能感兴趣的:(Unity3D)