Unity3d UNITY协同路由和回调数据同步

Unity3d UNITY协同路由和回调数据同步,unity3d,Unity3d,我必须从网上取很多照片,并把它们放在正确的主人名字旁边。我有一个纹理数组,以及它们对应的所有者ID 首先,我必须使用所有者的ID调用一个API函数来获取他们图片的URL,然后从该URL获取图片 下面是c#unity伪代码: void function() { for (int i=0; i<10; i++) { start_fetch_url(picID[i],CallBack); // fetch URL of picID, via call back

我必须从网上取很多照片,并把它们放在正确的主人名字旁边。我有一个纹理数组,以及它们对应的所有者ID

首先,我必须使用所有者的ID调用一个API函数来获取他们图片的URL,然后从该URL获取图片

下面是c#unity伪代码:

 void function() {
    for (int i=0; i<10; i++) {
       start_fetch_url(picID[i],CallBack); // fetch URL of picID, via call back 
    }
 }

 // when url is received this is called, then fetch pic at that URL
 IEnumerator CallBack(string url)
 {
    WWW fetchPic= new WWW(url);
    while (fetchPic.isDone) {
      yeild return new WaitForSeconds(0.1f);
    }
    texture[????]=fetchPic.texture; '// <--- here is problem, which texture
 }
void函数(){

对于(int i=0;i如果您无法更改
start\u fetch\u url
,并且无法根据传递给您的协同程序的
url
推断用户id,我认为唯一的方法是按顺序下载图像

您可以通过将用户索引保留在类变量中并仅在调用协同程序时转到下一张图片来实现这一点

var index = 0;

function load_next()
{
 //we've reached the end
 if( index == 10 )
 {
  return;
 }

 start_fetch_url(picID[i],CallBack);
}

// when url is received this is called, then fetch pic at that URL
IEnumerator CallBack(string url)
{
  WWW fetchPic= new WWW(url);

  while (fetchPic.isDone) 
  {
   yield return new WaitForSeconds(0.1f);
  }

  texture[index]=fetchPic.texture; 

  //continue with the fetching
  index++;
  load_next();
}
注意:您无需轮询以检查下载是否已结束,您只需调用
yield return fetchPic;
。如果需要显示进度条,则需要使用while作为当前状态