Last active
August 29, 2015 14:18
-
-
Save tsubaki/ecdf84e27e59ed6ce72d 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 System.Collections.Generic; | |
public class CoroutineSample1 : MonoBehaviour | |
{ | |
IEnumerator Start () | |
{ | |
Debug.Log ("start"); | |
var ie1 = download (); | |
var coroutine1 = StartCoroutine (ie1); | |
var ie2 = download (); | |
var coroutine2 = StartCoroutine (ie2); | |
//処理を待ち合わせる | |
yield return coroutine1; | |
yield return coroutine2; | |
// 戻り値を取得 | |
float downloadTime1 = (float)ie1.Current; | |
float downloadTime2 = (float)ie2.Current; | |
// 合計をログに出力 | |
float sum = downloadTime1 + downloadTime2; | |
Debug.LogFormat ("finish! same : {0}", sum); | |
} | |
IEnumerator download () | |
{ | |
// ランダムな秒数(0.2~1sec)間待つ | |
float waitSec = Random.Range (0.2f, 1f); | |
yield return new WaitForSeconds (waitSec); | |
// 戻り値を返す | |
yield return waitSec; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment