public void StartCoroutine(IEnumerator routine, coroutineCallBack callBack = null, bool asynchronous = false, string strName = "") { if (null == routine) { return; } coroutineJob job = new coroutineJob(); if (true == asynchronous) { //********* 비동기 ********** job.etorRoot = routine; job.etorCurrentDepth = routine; job.callBack = callBack; listCoroutine.Add(job); } else { //********** 동기 ********** //코루틴 수행 job.etorRoot = routine; job.etorCurrentDepth = routine; //int coroutineCount = 0; //float startTime = 0f; //float endTime = 0f; //float timeElapsed = 0f; //while(true) int processCount = 1; for (int i = 0; i < processCount; i++) //chamto test , while로 무한대로 돌리면 유니티에디터가 정지상태가 됨 { //Time 같은 유니티 전용함수를 쓰면 서버에서 컴파일이 안됨 //startTime = Time.realtimeSinceStartup; //timeElapsed += (endTime - startTime); //--------------------------------------------------------------------------------------------------- if (false == job.etorCurrentDepth.MoveNext()) { //******* 현재 코루틴 완료 ******* if (job.etorRoot == job.etorCurrentDepth) { //최상위 부모 코루틴으로 돌아왔을때 콜백호출후, 코루틴 처리를 마친다. if (null != callBack) { //콜백요청이 있다면 처리해 준다. callBack(job.etorCurrentDepth.Current); } DebugWide.Log("현재 코루틴 완료" + " " + strName); break; } else { processCount++; job.etorCurrentDepth = job.stackPrev.Pop(); } } //--------------------------------------------------------------------------------------------------- else { //******* 현재 코루틴 진행중 ******* processCount++; //DebugWide.Log("현재 코루틴 진행중" + " " + strName); if (null != job.etorCurrentDepth.Current && job.etorCurrentDepth.Current is IEnumerator) { job.stackPrev.Push(job.etorCurrentDepth); job.etorCurrentDepth = job.etorCurrentDepth.Current as IEnumerator; } }//end else //System.Threading.Thread.Sleep(10); //while 문에서 CPU계속 점유하는 현상이 있어 넣어봄 //--------------------------------------------------------------------------------------------------- //endTime = Time.realtimeSinceStartup; } //end while } //end else }
public void Start_Async(IEnumerator routine, coroutineCallBack callBack = null, string strName = "") { this.StartCoroutine(routine, callBack, MODE_ASYNCHRONOUS, strName); }