解决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());

©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值