我正试图通过调用协程(使用更高效的协程资产(从Firestore存储url加载图像。然而,郊游并没有到来,我不明白为什么。。。
public void displayImage(string url)
{
Debug.Log("called display image: "+ url);
Timing.RunCoroutine(_loadImageSingle(url));
}
public IEnumerator<float> _loadImageSingle(string url)
{
Debug.Log("Loading ....");
WWW wwwLoader = new WWW(url);
yield return Timing.WaitUntilDone(wwwLoader);
singleimg.texture = wwwLoader.texture;
}
真的很感激任何指点!
Unity中的推论仅为IEnumerator
,没有任何返回值!
然后你必须使用StartCoroutine
来运行它。。。我想这发生在你没有显示的代码中?
public void displayImage(string url)
{
Debug.Log("called display image: "+ url);
Timing.RunCoroutine(_loadImageSingle(url));
}
private IEnumerator _loadImageSingle(string url)
{
Debug.Log("Loading ....");
WWW wwwLoader = new WWW(url);
yield return Timing.WaitUntilDone(wwwLoader);
singleimg.texture = wwwLoader.texture;
}
一般注意,WWW
已过时。您应该使用UnityWebRequestTexture.GetTexture
:
private IEnumerator _loadImageSingle(string url)
{
Debug.Log("Loading ....");
using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(url))
{
yield return uwr.SendWebRequest();
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log(uwr.error);
}
else
{
// Get downloaded texture
singleimg.texture = DownloadHandlerTexture.GetContent(uwr);
}
}
}