[MenuItem("bat/merge")]
public static void merge(){
Process p = GetNewProcess("git_merge.bat")
p.Exited =(obj,e)=>{
if(p.ExitCode == -1) return;
Debug.Log(p.ExitCode);
...
// following code would not run
Debug.Log(PlayerSettings.bundleVersion);
if(Application.isPlaying)...
}
p.Start();
}
沒有例外被拋出。似乎如果我嘗試獲取一些與編輯器相關的值,該程序將被終止。
uj5u.com熱心網友回復:
大多數 Unity API 只能從 Unity 主執行緒訪問。
該事件p.Exited很可能不是在該執行緒上呼叫的,而是異步的。
=> 您需要在 Unity 主執行緒中運行一個“主執行緒調度程式”并等待您的結果
通常你在運行時使用 aMonoBehaviour但在這種情況下它是一個編輯器腳本所以你可以去
[MenuItem("bat/merge")]
public static void merge()
{
Process p = GetNewProcess("git_merge.bat");
p.Exited = (obj, e) =>
{
// Instead of directly executing your code you instead
// move it into a callback function
void MainThreadCallback()
{
// Since you want to execute this only once remove the callback
EditorApplication.update -= MainThreadCallback;
// I would put this first just for debugging reasons ;)
Debug.Log(p.ExitCode);
if (p.ExitCode == -1) return;
Debug.Log(PlayerSettings.bundleVersion);
if (Application.isPlaying)
{
//...
}
}
// Then you tell the editor to call your callback
// with the next global editor update
EditorApplication.update = MainThreadCallback;
};
p.Start();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/536475.html
標籤:C#unity3d
上一篇:如何縮放瓦片地圖上的特定瓦片?
