InjectFix
InjectFix copied to clipboard
Unity2021 能对async做补丁, 但不能使用await
[IFix.Patch]
public async void OnBtnStart()
{
Debug.Log("---111---");
m_VersionText.text = 1.ToString();
if (m_Started)
{
return;
}
Debug.Log("---2222---");
await Task.Delay(3000);
m_VersionText.text = 2.ToString();
Debug.Log("---333---");
Output:
11-25 17:25:33.413 2475 2491 I Unity : ---111---
11-25 17:25:33.419 2475 2491 I Unity : ---2222---
后面的代码没运行
[IFix.Patch]
public async void OnBtnStart()
{
Debug.Log("-----1---------");
if (m_Started)
{
return;
}
Debug.Log("-----2---------");
m_Started = true;
await UniTask.WaitUntil(()=>Game.AB.IsReady);
Debug.Log("-----3---------");
await Game.Scene.LoadScene(AssetPathHelper.LocateScene("MapScene"));
Debug.Log("-----4---------");
}
Output:
11-29 15:17:01.278 6978 6997 I Unity : -----3---------
11-29 15:17:01.309 6978 6997 I Unity : -----1---------
11-29 15:17:01.310 6978 6997 I Unity : -----2---------
运行次序不正常
+1
+1
+10086