[UnityxWinCmd][工具鏈]如何在Unity里調(diào)用編寫好的命令行程序

最近做工程遇到一點小麻煩。

項目是一個WebGL項目,Unity負責展示和表現(xiàn),后端C++寫了一套算法,Unity提供數(shù)據(jù),算法算完了返回數(shù)據(jù)顯示。

看起來很簡單,但是調(diào)試起來簡直要死人了:每次調(diào)試都需要發(fā)布->清除瀏覽器緩存->重新打開瀏覽器進入工程->測試。最要命的是WebGL平臺我現(xiàn)在還沒有發(fā)現(xiàn)什么比較好的工具來輔助調(diào)試,只能通過原始的打Log來猜測發(fā)生了什么。這可以說極大的拖慢了我的開發(fā)進度。

為了解決這些問題,稍微百度了一下,參考了文章 的內(nèi)容,做了一套簡單工具。

核心還是上文中的代碼

private static void processCommand(string command, string argument, Action<string> handler)
    {
        ProcessStartInfo start = new ProcessStartInfo(command);
        start.Arguments = argument;
        start.CreateNoWindow = false;
        start.ErrorDialog = true;
        start.UseShellExecute = false;

        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.UTF8Encoding.UTF8;
            start.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
        }

        Process p = Process.Start(start);

        if (!start.UseShellExecute)
        {
            handler.Invoke(p.StandardOutput.ReadToEnd());
        }

        p.WaitForExit();
        p.Close();
    }

稍稍加了一點封裝,畢竟我也是要利用和處理輸出字符串的。

然后綁定到編輯器擴展或者臨時UI的按鈕事件去,就可以用了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容