Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

泛型 Task<T>函式呼叫後會卡住 #223

Closed
leejack1000 opened this issue Oct 26, 2018 · 0 comments
Closed

泛型 Task<T>函式呼叫後會卡住 #223

leejack1000 opened this issue Oct 26, 2018 · 0 comments

Comments

@leejack1000
Copy link

public static async Task instantiateObjectAsync(T templateObject, Transform parent = null, bool worldPositionStays = false) where T : UnityEngine.Object
{
await Task.Delay(16);
return UnityEngine.Object.Instantiate(templateObject, parent, worldPositionStays);
}
public static async Task instantiateObjectAsync(Task loadTemplateObject, Transform parent = null, bool worldPositionStays = false)
{
GameObject templateObject = await loadTemplateObject;

return await instantiateObjectAsync(templateObject, parent, worldPositionStays);

}

public static async Task instantiateObjectAsync(Task loadTemplateObject, Transform parent = null, bool worldPositionStays = false) where T : UnityEngine.Object
{
T templateObject = await loadTemplateObject;

return await instantiateObjectAsync<T>(templateObject, parent, worldPositionStays);

}

public static Task loadTask()
{
return Task.FromResult(new GameObject());
}

private static async Task Test()
{
Debug.Log("1");
GameObject obj1 = await instantiateObjectAsync(new GameObject());
Debug.Log("2");
GameObject obj2 = await instantiateObjectAsync(loadTask());
Debug.Log("3");
}

以上程式碼從 Test() 進入
會卡在 Debug.Log("2"); 不會進到 Debug.Log("3");

@leejack1000 leejack1000 changed the title Task<T>當成參數傳遞會卡住 泛型 Task<T>函式呼叫後會卡住 Oct 26, 2018
liiir1985 added a commit that referenced this issue Jun 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant