コード例 #1
0
        public static IDisposableItem AsDisposable(this RoutineHandle handler)
        {
            var disposable = ClassPool.Spawn <DisposableAction>();

            disposable.Initialize(() => UniRoutineManager.TryToStopRoutine(handler));
            return(disposable);
        }
コード例 #2
0
        public static IDisposableItem AddTo(this RoutineHandle handler, ICollection <IDisposable> collection)
        {
            var disposable = handler.AsDisposable();

            collection.Add(disposable);
            return(disposable);
        }
コード例 #3
0
        /// <summary>
        /// start uniroutine interator
        /// </summary>
        /// <param name="enumerator">target enumerator</param>
        /// <param name="routineType">routine type</param>
        /// <param name="scope">routine execution scope</param>
        /// <param name="moveNextImmediately"></param>
        /// <returns>cancelation handle</returns>
        public static RoutineHandle RunUniRoutine(
            IEnumerator enumerator,
            RoutineType routineType,
            RoutineScope scope,
            bool moveNextImmediately = true)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(new RoutineHandle());
            }
#endif

            var routineObject = GetRoutineObject(scope);
            //get routine
            var routine = routineObject.GetRoutine(routineType);
            //add enumerator to routines
            var routineTask = routine.AddRoutine(enumerator, moveNextImmediately);
            if (routineTask == null)
            {
                return(new RoutineHandle(0, routineType, scope));
            }

            var routineValue = new RoutineHandle(routineTask.Id, routineType, scope);
            return(routineValue);
        }
コード例 #4
0
        public static RoutineHandle WithFinally(this RoutineHandle handle, Action action)
        {
            if (action == null)
            {
                return(handle);
            }

            UniRoutineManager.AddFinally(handle, action);
            return(handle);
        }
コード例 #5
0
        public static bool AddFinally(RoutineHandle handler, Action action)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(false);
            }
#endif
            //get routine
            var scope   = GetRoutineObject(handler.Scope);
            var routine = scope.GetRoutine(handler.Type);
            return(routine.AddFinally(handler.Id, action));
        }
コード例 #6
0
        public static bool IsRoutineActive(RoutineHandle handler)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(false);
            }
#endif
            //get routine
            var scope   = GetRoutineObject(handler.Scope);
            var routine = scope.GetRoutine(handler.Type);
            return(routine.IsActive(handler.Id));
        }
コード例 #7
0
        public static bool TryToStopRoutine(RoutineHandle handler)
        {
#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                return(false);
            }
#endif
            //get routine
            var scope   = GetRoutineObject(handler.Scope);
            var routine = scope.GetRoutine(handler.Type);
            //add enumerator to routines
            return(routine.CancelRoutine(handler.Id));
        }
コード例 #8
0
 public static RoutineHandle AddTo(this RoutineHandle handler, ILifeTime lifeTime)
 {
     lifeTime.AddCleanUpAction(() => handler.Cancel());
     return(handler);
 }
コード例 #9
0
 public static ILifeTime AddTo(this RoutineHandle handle, Component component)
 {
     return(component.AddTo(() => handle.Cancel()));
 }
コード例 #10
0
 public static bool IsActive(this RoutineHandle handler)
 {
     return(UniRoutineManager.IsRoutineActive(handler));
 }
コード例 #11
0
 public static bool Cancel(this RoutineHandle handler)
 {
     return(UniRoutineManager.TryToStopRoutine(handler));
 }