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 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); } }