Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created April 27, 2017 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/800f9f784121e48fb11dc690e9b3bf11 to your computer and use it in GitHub Desktop.
Save flushpot1125/800f9f784121e48fb11dc690e9b3bf11 to your computer and use it in GitHub Desktop.
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