예제 #1
0
        /// <summary>
        /// 初始化协程。
        /// </summary>
        /// <param name="customCoroutineCreator">自定义协程创建器,若为空则调用全局协程</param>
        /// <param name="customCoroutineTeminator">自定义协程终止器,若为空则调用全局协程</param>
        public void Initialization(CoroutineCreator customCoroutineCreator = null, CoroutineTeminator customCoroutineTeminator = null)
        {
            mCoroutineCreator   = customCoroutineCreator;
            mCoroutineTeminator = customCoroutineTeminator;

            if (mCoroutineCreator == null)
            {
                mCoroutineCreator = (enumerator) => CoroutineHelper.StartCoroutine(enumerator);
            }

            if (mCoroutineTeminator == null)
            {
                mCoroutineTeminator = (enumerator) => CoroutineHelper.StopCoroutine(enumerator);
            }

            for (int i = 0, iMax = mCoroutinesArray.Length; i < iMax; i++)
            {
                var coroutineInfo = new CoroutineInfo();
                coroutineInfo.Task = new Task();
                coroutineInfo.Task.Init();
                coroutineInfo.Task.OnTaskFinished = DetectTaskWaitCoroutine;

                var coroutine = mCoroutineCreator(coroutineInfo.Task.Tick());

                coroutineInfo.Coroutine = coroutine;

                mCoroutinesArray[i] = coroutineInfo;
            }

            mIsInitialized = true;
        }
 public void Reset()
 {
     _instance = null;
     StopAllCoroutines();
     CancelInvoke();
     this.DestroyAll();
 }