Exemple #1
0
        /// <summary>
        /// 扔到协程中执行
        /// 如果指明了owner,那么当owner=null时协程将自动被回收不予执行
        /// 如果指明了f,那么当有异常时会自动调用f来进行收尾工作,相对于try块的finally语句
        /// </summary>
        public static YCCoroutine DispatchService(IEnumerator c,
                                                  GameObject owner, CoroutineErrorCallback f)
        {
            YCContext ycc = new YCContext(c, owner);

            // 立刻先执行一把
            try
            {
                ycc.Step();
            }
            catch (System.Exception e)
            {
                // 有报错,需要进行收尾操作,并摘除掉
                ycc.Error();
                UnityEngine.Debug.LogError(e);
                return(null);
            }

            if (ycc.IsFinished())
            {
                // 立刻就执行完毕了,就不要加到队列中
                return(null);
            }

            // 加到队列中继续执行
            queue.Add(ycc);
            return(new YCCoroutine(ycc, owner, f));
        }
Exemple #2
0
 public YCCoroutine(YCContext c, GameObject owner, CoroutineErrorCallback f)
 {
     this.context  = c;
     this.owner    = owner;
     this.hasOwner = (owner != null);
     this.f        = f;
 }