예제 #1
0
        //private Coroutine(RecurranceParameters recurranceParameters = null)
        //{
        //    this.RecurranceParameters = recurranceParameters;
        //}

        public static Coroutine Start(IEnumerator coroutine, object owner = null, RecurranceParameters recurranceParameters = null)
        {
            var host = GetCoroutineHost(owner);

            var c = new Coroutine();
            c.State = host.EnqueueCoroutine(coroutine, recurranceParameters);
            return c;
        }
예제 #2
0
        /// <summary>
        /// Run coroutine once immediately.  Returns null if the coroutine finished.
        /// </summary>
        /// <param name="owner">owner must provide a CoroutineHost by implementing IHasCoroutineHost.CoroutineHost, or the static Coroutine.DefaultCoroutineHost must be set</param>
        /// <param name="coroutine"></param>
        /// <param name="recurranceParameters"></param>
        /// <returns></returns>
        public static Coroutine StartImmediately(IEnumerator coroutine, object owner = null, RecurranceParameters recurranceParameters = null)
        {
            var host = GetCoroutineHost(owner);

            var state = host.RunCoroutine(coroutine, recurranceParameters);
            if (state == null) return null; // Finished right away

            var c = new Coroutine();
            c.State = state;
            return c;
        }
예제 #3
0
        protected override BehaviorStatus OnStart()
        {            
#if RequirePollTargetBehaviorContext            
            if (Context == null)
            {
                TryGetContextFromPollTarget();
            }            
            //if (Context == null) throw new Exception("RequirePollTargetBehaviorContext");
            if (Context == null) throw new Exception("RequirePollerBehaviorContext");
#endif

#if MAX_RECURRANCES
            recurrancesRemaining = RecurranceParameters.MaxRecurrances;
#endif

#if NO_COROUTINES
            var hasPP = pollTarget as IHasPollingProvider;
            if (hasPP != null && hasPP.PollingProvider != null)
            {
                hasPP.PollingProvider.Register(this);
            }
            else
            {
#if CheckPollTargetForIPollingProvider
                var ipp = pollTarget as IPollingProvider;
                if (ipp != null)
                {
                    ipp.Register(this);
                }
                else
#endif
                {
                    var pp = Dependencies.PollingProvider;
                    if (pp == null) throw new InvalidOperationException(NoPollerMessage);
                    pp.Register(this);
                }
            }
#else
            // Can't do run here because it might fail before we can set it to running :-/.  But pollers
            // shouldn't have to run immediately.
            coroutine = Coroutine.Start(this,this.Context, this.RecurranceParameters);
            coroutine.SetName(this.GetType().Name);
#endif
            //if (RecurranceParameters.StartImmediately) { DoPoll(); }
            return BehaviorStatus.Running;
        }
 private void StopCoroutine()
 {
     var c = coroutine;
     if (c != null)
     {
         coroutine = null;
         c.Dispose();
     }
 }
        private void Suspend()
        {
          
#if BehaviorPoller_SuspendAndResume
#endif
            if (coroutine != null)
            {
                coroutine.Suspend();
            }
            StopCoroutine();

            var c = coroutine;
            if (c != null)
            {
                coroutine = null;
                c.Dispose();
            }
        }
 private void StartCoroutine()
 {
     coroutine = Coroutine.Start(this, behavior.Context, this.recurranceParameters);
 }