コード例 #1
0
        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);
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: Encampment.cs プロジェクト: JoelPlourde/Shore-Squad
        public void RegisterTask(ITaskArguments taskArguments)
        {
            Tasks.Enqueue(taskArguments);

            if (!IsInvoking())
            {
                InvokeRepeating(nameof(Routine), 0f, Constant.TICK_RATE / 1000f);
            }
        }
コード例 #4
0
ファイル: Interact.cs プロジェクト: JoelPlourde/Shore-Squad
 public override void Combine(ITaskArguments taskArguments)
 {
     base.Initialize(taskArguments, TaskPriority);
     if (trigger)
     {
         trigger.Destroy();
     }
     Execute();
 }
コード例 #5
0
 public override void Combine(ITaskArguments taskArguments)
 {
     base.Initialize(taskArguments, TaskPriority);
     Execute();
 }
コード例 #6
0
 // Define the behaviour when two task of the same type are combined.
 public abstract void Combine(ITaskArguments taskArguments);
コード例 #7
0
 public virtual void Initialize(ITaskArguments taskArguments, TaskPriority taskPriority)
 {
     TaskArguments = taskArguments;
     TaskPriority  = taskPriority;
 }