Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using UnityEngine;
using System.Collections;
using SpicyPixel.Threading;
using SpicyPixel.Threading.Tasks;
public class AsyncSample : ConcurrentBehaviour {
void Update(){
If(Input.GetKeyDown(KeyCode.F){
sample();
}
}
void sample(){
/*ここまでで、nodesに関する宣言や処理が実施済みとする*/
/*nodesは複数個ある=getImage()は複数回呼び出されるとする*/
foreach (var node in nodes) {
taskFactory.StartNew(getImage(node.Attributes["href"].Value));
}
}
/*一般的なコルーチンに対応した使い方で良い*/
IEnumerator getImage(string urlText) {
WWW www = new WWW(urlText);
yield return www;
if (!string.IsNullOrEmpty(www.error)) {
Debug.LogError(string.Format("Fail!\n{0}", www.error));
yield break;
}
/*取得したwwwの情報を使う処理が入る*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment