Coroutine
2 분
코루틴은 실행을 일시 중지한 다음 중단된 지점에서 계속 진행하는 비선점 멀티태스킹 프로그램 구성 요소입니다. 주로 비동기 작업, 예외, 이벤트 루프, 반복자, 무한 목록 및 파이프와 같은 기능을 실행하는 데 사용됩니다.
여기를 클릭하여 Unity의 코루틴에 대해 더 알아보세요.
Unity 코루틴의 ZEPETO 스크립트 구현은 다음과 같습니다.
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { WaitForSeconds } from 'UnityEngine';
export default class Coroutine extends ZepetoScriptBehaviour {
private current: number;
Start() {
this.current = 0;
console.log(`start routine`);
this.StartCoroutine(this.DoRoutine());
}
*DoRoutine() {
while(true) {
yield null;
console.log(`[${this.current++}] Wait to next routine..`);
yield new WaitForSeconds(1);
}
}
}아래의 테스트 코드 출력 화면을 확인하세요.
