public void CreateTask <T>(ITaskArguments taskArguments, TaskPriority taskPriority = TaskPriority.NORMAL) where T : TaskBehaviour { if (!ReferenceEquals(_currentTask, null) && taskPriority >= _currentTask.TaskPriority) { CancelTask(); TaskBehaviour taskBehaviour = gameObject.AddComponent <T>(); taskBehaviour.Initialize(taskArguments, taskPriority); AddTask(taskBehaviour); return; } // Verify if the new Task is the same as an existing task, if so combine them. if (!ReferenceEquals(_currentTask, null) && _currentTask.TaskArguments.GetTaskType() == taskArguments.GetTaskType()) { _currentTask.Combine(taskArguments); return; } if (_taskBehaviours.Count > 0 && _taskBehaviours.Peek().TaskArguments.GetTaskType() == taskArguments.GetTaskType()) { // It is the same as the next one, therefore don't recreate a task for nothing. _taskBehaviours.Peek().Initialize(taskArguments, taskPriority); } else { TaskBehaviour taskBehaviour = gameObject.AddComponent <T>(); taskBehaviour.Initialize(taskArguments, taskPriority); AddTask(taskBehaviour); } }
public void CreateTask(ITaskArguments taskArguments, TaskPriority taskPriority = TaskPriority.NORMAL) { MethodInfo methodInfo = typeof(TaskScheduler).GetMethods().Where(x => x.Name == "CreateTask").Where(x => x.IsGenericMethod).First(); methodInfo = methodInfo.MakeGenericMethod(TaskTypes[taskArguments.GetTaskType()]); object[] args = { taskArguments, taskPriority }; methodInfo.Invoke(this, args); }
public void RegisterTask(ITaskArguments taskArguments) { Tasks.Enqueue(taskArguments); if (!IsInvoking()) { InvokeRepeating(nameof(Routine), 0f, Constant.TICK_RATE / 1000f); } }
public override void Combine(ITaskArguments taskArguments) { base.Initialize(taskArguments, TaskPriority); if (trigger) { trigger.Destroy(); } Execute(); }
public override void Combine(ITaskArguments taskArguments) { base.Initialize(taskArguments, TaskPriority); Execute(); }
// Define the behaviour when two task of the same type are combined. public abstract void Combine(ITaskArguments taskArguments);
public virtual void Initialize(ITaskArguments taskArguments, TaskPriority taskPriority) { TaskArguments = taskArguments; TaskPriority = taskPriority; }