【发布时间】:2020-09-15 12:11:37
【问题描述】:
问候,
我目前面临协程无法启动的问题。这是我第一次遇到这个问题,我在网上找不到合适的解决方案。如果有人能指出正确的方向来解决这个问题,我们将不胜感激。
这里是代码。
path_reference.GetDownloadUrlAsync().ContinueWith((Task<Uri> task) => {
if (!task.IsFaulted && !task.IsCanceled)
{
Debug.Log("Download URL: " + task.Result);
StartCoroutine(DownloadStuff(task.Result));
}
else
{
Debug.Log(task.Exception.ToString());
}
});
}
IEnumerator DownloadStuff(Uri uri)
{
Debug.Log("Start Download");
using (var www = UnityWebRequestTexture.GetTexture(uri))
{
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
var texture = DownloadHandlerTexture.GetContent(www);
//Texture2D texture = new Texture2D(1, 1);
//if you need sprite for SpriteRenderer or Image
Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width,
texture.height), new Vector2(0.5f, 0.5f), 100.0f);
Debug.Log("Finished downloading!");
}
Debug.Log(www.downloadProgress);
}
}'
【问题讨论】:
-
当你说“无法开始?”你到底是什么意思?当你尝试运行它时会发生什么?
-
代码运行了,但是当它应该启动协程时,什么也没发生。
-
是否给出了任何调试消息?
-
NO,即使在协程 "Debug.Log("Start Download");"甚至没有出现。
-
看起来协程被正确调用,所以问题可能出在其他地方。 “不”是指甚至不是
Debug.Log("Download URL: etc..?如果是这样,那么问题肯定出在其他地方。尝试将!task.IsFaulted && !task.IsCanceled更改为true
标签: firebase unity3d coroutine