最近做工程遇到一點小麻煩。
項目是一個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的按鈕事件去,就可以用了。