【3Dゲームエンジン】Unity質問スレッド10at GAMEDEV【3Dゲームエンジン】Unity質問スレッド10 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト1010:名前は開発中のものです。 14/08/03 11:33:26.43 uKgi7+K6.net >>976 そう思うじゃん? けどIEnumeratorだけだと2フレーム以上待機してくれないんだよ… 2フレーム位上待機させるならコルーチンと同じくStartCoroutineが必要… StartCoroutineの記述を省略したいんだけどWaitForSecondsとか中身どうなってるんだろう… using System.Collections; using UnityEngine; public class Sample : MonoBehaviour { void Start() { StartCoroutine( Routine() ); } IEnumerator Routine() { while( true ) { Debug.Log( Time.frameCount ); //yield return StartCoroutine( new WaitForFrame( 10 ) ); // これはしっかり10フレーム待機する。 yield return new WaitForFrame( 10 ); // これはMoveNextが1回も呼ばれない。 } } } 1011:名前は開発中のものです。 14/08/03 11:34:51.28 uKgi7+K6.net >>981の続き // コンストラクタで渡されたフレーム数だけコルーチン内で待機するクラス class WaitForFrame : YieldInstruction, IEnumerator { readonly int maxWaitFrameCount; int waitFrameCount; public WaitForFrame( int maxWaitFrameCount ) { this.maxWaitFrameCount = maxWaitFrameCount; } object IEnumerator.Current { get { return null; } } bool IEnumerator.MoveNext() { waitFrameCount++; return waitFrameCount <= maxWaitFrameCount; } void IEnumerator.Reset() { waitFrameCount = 0; } } 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch