1
현재 2 가지 기능이 있습니다.코 루틴에서 스프라이트 반환하기
내 첫 번째 이미지는 IEnumerator
입니다. LoadImage
으로 전화를 걸고 URL에서 이미지를 다운로드합니다.
IEnumerator LoadImage()
{
WWW www = new WWW("https://s3-ap-northeast-1.amazonaws.com/myeyehouse/uimg/scimg/sc661120171130095837184/pano/thumb_Eyehouse.jpg");
while (!www.isDone)
{
Debug.Log("Download image on progress" + www.progress);
yield return null;
}
if (!string.IsNullOrEmpty(www.error))
{
Debug.Log("Download failed");
}
else
{
Debug.Log("Download succes");
Texture2D texture = new Texture2D(1, 1);
www.LoadImageIntoTexture(texture);
Sprite sprite = Sprite.Create(texture,
new Rect(0, 0, texture.width, texture.height), Vector2.zero);
return sprite;
}
}
내 두 번째 기능은 할당 할 필요가 나의 GameObject
에 (스프라이트입니다) LoadImage()
의 출력. 나는 단지 GameObject
을 넣고 LoadImage()
함수에로드 할 수 없습니다. 가능한 경우, LoadImage()
함수에서 스프라이트를 어떻게 할당 할 수 있는지에 대한 조언이 필요합니다.
IEnumerator를 반환하는 이유는 무엇입니까? 0 또는 1 개의 스프라이트 뒤에 0 개 이상의 null 세트가 제공됩니다. 실패 할 경우 'Sprite'또는 'null'을 반환하지 않는 이유는 무엇입니까? – juharr
@juharr 아 그래, 그게 무슨 뜻이야. 내 코드에서 볼 수 있듯이, 나는 'yield return sprite'를 가지고있다. 선. 어떻게 두 번째 함수로 호출 할 수 있습니까? – zoenightshade
'yield return null;은 버그 일 가능성이 높습니다. 또한 비 제네릭 IEnumerator를 사용하지 마십시오. 항상'IEnumerator'또는 파생 형식을 사용하면 @juharr이 무엇을 얻고 있는지 이해할 수 있습니다. –