, IEnumerator Unity Coroutine. , , - , ? , Unity / Unity Remote. Coroutines, , Thread, .
Coroutine:
void SomeMethod() {
StartCoroutine(Threaded());
}
IEnumerator Threaded() {
yield return new WaitForSeconds(3f);
}
WWW class IEnumerator
OP:
, Coroutine
OPs:
/. : . , , , .
void ButtonClicked() {
SetTexture()
}
void SetTexture() {
Texture texture = GetTexture()
Object.texture = texture;
}
Texture GetTexture() {
Texture texture;
StartCoroutine(DownloadTexture((textureCallback) => {
texture = textureCallback;
}));
return texture;
}
IEnumerator DownloadTexture(Action<Texture> callbackTexture)
{
WWW www = new WWW(URL);
yield return www;
callback(www.texture);
}
, Coroutine , .
,
โ โ โ โ
:
โ โ โ
:
void ButtonClick() {
StartCoroutine(DownloadTexture((callbackTexture) => {
SetTexture(callbackTexture);
}));
}
IEnumerator DownloadTexture(Action<Texture> callbackTexture)
{
WWW www = new WWW(URL);
yield return www;
callback(www.texture);
}
void SetTexture(Texture texture) {
object.texture = texture;
}
, . -, byte [] Texture, , Button, . / .