ユーザ用ツール

サイト用ツール

wiki:unity:tips:115

以前のリビジョンの文書です


115 StartCoroutineを使わずコルーチンを回す

using UnityEngine;
using System.Collections;
 
public class TestCoroutine : MonoBehaviour
{
    private IEnumerator m_Enumerator;
 
    void Start ()
    {
        m_Enumerator = CustomProcess();
    }
 
    IEnumerator CustomProcess()
    {
        Debug.Log("wait");
        yield return null;
 
        Debug.Log("Complete!!!");
        yield break;
    }
 
    void Update ()
    {
        if( m_Enumerator != null )
        {
            // 次のフレームへ進めている。
            bool result = m_Enumerator.MoveNext();
            if (result)
            {
                Debug.Log("Next.");
            }
            else
            {
                // コルーチン終了。
                Debug.Log("End.");
                m_Enumerator = null;
            }
        }        
    }
}

MoveNext を呼ばなければ一時停止扱いにでも出来る。独自のカスタマイズが可能となる。

Permalink wiki/unity/tips/115.1474469602.txt.gz · 最終更新: 2016/09/21 14:53 by step

oeffentlich