Ejemplo n.º 1
0
    public void Update()
    {
        //foreach (coroutineJob etor in listCoroutine)
        coroutineJob etor = null;

        for (int i = 0; i < listCoroutine.Count; i++)
        {
            etor = listCoroutine[i] as coroutineJob;
            if (null == etor)
            {
                //Debug.Log("WideUseCoroutine-Update cast Error+----------------");
                continue;
            }
            //---------------------------------------------------------------------------------------------------
            //자식코루틴까지 탐색하여 모두 진행시킨다.
            if (false == etor.etorCurrentDepth.MoveNext())
            {   //******* 현재 코루틴 완료 *******
                //DebugWide.Log("false == etor.etorCurrentDepth.MoveNext");

                if (etor.etorCurrentDepth == etor.etorRoot)
                {   //최상위 부모 코루틴이 완료되었다면, 완료된 코루틴이기 때문에 제거한다.
                    listEndCoroutine.Add(etor);
                    if (null != etor.callBack)
                    {
                        etor.callBack(etor.etorRoot.Current);
                    }
                }
                else
                {   //자식코루틴이 완료되었다면, 전 부모 코루틴으로 변경한다.
                    etor.etorCurrentDepth = etor.stackPrev.Pop();
                }
            }
            //---------------------------------------------------------------------------------------------------
            else
            {   //******* 현재 코루틴 진행중 *******
                //DebugWide.Log("true == etor.etorCurrentDepth.MoveNext : " + etor.etorCurrentDepth.Current + "  type :" + etor.etorCurrentDepth.Current.GetType() + "  :  "+typeof(IEnumerator));

                //IEnumerator 자식코루틴이 있는지 검사
                if (null != etor.etorCurrentDepth.Current && etor.etorCurrentDepth.Current is IEnumerator)
                {
                    //DebugWide.Log("자식 코루틴 있음 : " + etor.etorCurrentDepth.Current);

                    //자식 코루틴이 있다면, 현재코루틴을 스택에 넣고, 자식코루틴을 현재코루틴으로 한다.
                    etor.stackPrev.Push(etor.etorCurrentDepth);
                    etor.etorCurrentDepth = etor.etorCurrentDepth.Current as IEnumerator;
                } //end if
            }     //end if
             //---------------------------------------------------------------------------------------------------
        }         //end foreach


        //작업이 끝난 코루틴 모두 제거
        foreach (coroutineJob endEtor in listEndCoroutine)
        {
            listCoroutine.Remove(endEtor);
        }

        listEndCoroutine.Clear();
    }
Ejemplo n.º 2
0
    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
    }