Created
April 27, 2017 19:42
-
-
Save flushpot1125/800f9f784121e48fb11dc690e9b3bf11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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