Beispiel #1
0
        public bool CancelTask(ITask t)
        {
            SimpleTask task = (SimpleTask)t;

            task.IsCancelled = true;
            return(tasks.Remove(task));
        }
Beispiel #2
0
        public ITask ScheduleNextAsyncFrame(ILifecycleObject @object, Action action, string taskName)
        {
            SimpleTask task = new SimpleTask(this, @object, action, ExecutionTargetContext.NextAsyncFrame);

            TriggerEvent(task);
            return(task);
        }
Beispiel #3
0
        public ITask ScheduleEveryPhysicUpdate(ILifecycleObject @object, Action action, string taskName)
        {
            SimpleTask task = new SimpleTask(this, @object, action, ExecutionTargetContext.EveryPhysicsUpdate);

            TriggerEvent(task);
            return(task);
        }
Beispiel #4
0
        private void TriggerEvent(SimpleTask task, EventCallback cb = null)
        {
            TaskScheduleEvent e = new TaskScheduleEvent(task);

            if (!(task.Owner is IEventEmitter owner))
            {
                return;
            }

            if (!task.Owner.IsAlive)
            {
                return;
            }

            IEventManager eventManager = container.Resolve <IEventManager>();

            eventManager?.Emit(owner, e, @event =>
            {
                task.IsCancelled = e.IsCancelled;

                if (!e.IsCancelled)
                {
                    tasks.Add(task);
                }

                cb?.Invoke(owner, @event);
            });
        }
Beispiel #5
0
        public ITask ScheduleUpdate(ILifecycleObject @object, Action action, string taskName, ExecutionTargetContext target)
        {
            SimpleTask task = new SimpleTask(this, @object, action, target);

            TriggerEvent(task, (sender, @event) =>
            {
                if (target != ExecutionTargetContext.Sync && @object.IsAlive)
                {
                    return;
                }

                if (((ICancellableEvent)@event).IsCancelled)
                {
                    return;
                }

                action();
                tasks.Remove(task);
            });

            return(task);
        }