Beispiel #1
0
 /** called when a task gets ended with an external call, meaning not coming from UGameplayTasksComponent mechanics */
 private void OnTaskEnded(UGameplayTask Task)
 {
     if (Task.RequiresPriorityOrResourceManagement())
     {
         RemoveResourceConsumingTask(Task);
     }
 }
Beispiel #2
0
        private void AddTaskToPriorityQueue(UGameplayTask NewTask)
        {
            bool bStartOnTopOfSamePriority = NewTask.GetResourceOverlapPolicy() == ETaskResourceOverlapPolicy.StartOnTop;
            int  InsertionPoint            = -1;

            for (int Idx = 0; Idx < TaskPriorityQueue.Count; ++Idx)
            {
                if (TaskPriorityQueue[Idx] == null)
                {
                    continue;
                }

                if ((bStartOnTopOfSamePriority && TaskPriorityQueue[Idx].GetPriority() <= NewTask.GetPriority()) ||
                    (!bStartOnTopOfSamePriority && TaskPriorityQueue[Idx].GetPriority() < NewTask.GetPriority()))
                {
                    TaskPriorityQueue.Insert(Idx, NewTask);
                    InsertionPoint = Idx;
                    break;
                }
            }

            if (InsertionPoint == -1)
            {
                TaskPriorityQueue.Add(NewTask);
            }
        }
Beispiel #3
0
        public virtual void OnGameplayTaskActivated(UGameplayTask Task)
        {
            KnownTasks.Add(Task);

            if (Task.IsTickingTask())
            {
                if (!TickingTasks.Contains(Task))
                {
                    TickingTasks.Add(Task);
                }
                // If this is our first ticking task, set this component as active so it begins ticking
                if (TickingTasks.Count == 1)
                {
                    UpdateShouldTick();
                }
            }

            if (!Task.IsOwnedByTasksComponent())
            {
                var TaskOwner = Task.GetTaskOwner();
                if (TaskOwner != null)
                {
                    TaskOwner.OnGameplayTaskActivated(Task);
                }
            }
        }
Beispiel #4
0
        public virtual void OnGameplayTaskInitialized(UGameplayTask Task)
        {
            // only one child task is allowed
            if (ChildTask != null)
            {
                Debug.LogWarning(">> terminating previous child task: %s");
                ChildTask.EndTask();
            }

            ChildTask = Task;
        }
Beispiel #5
0
        /// <summary>
        /// 删除传入的task, 本是是放在任务队列中
        /// </summary>
        public void RemoveResourceConsumingTask(UGameplayTask Task)
        {
            var e = new FGameplayTaskEventData(EGameplayTaskEvent.Remove, Task);

            TaskEvents.Add(e);
            // trigger the actual processing only if it was the first event added to the list
            if (TaskEvents.Count == 1 && CanProcessEvents())
            {
                ProcessTaskEvents();
            }
        }
Beispiel #6
0
        private void RemoveTaskFromPriorityQueue(UGameplayTask Task)
        {
            int RemovedTaskIndex = TaskPriorityQueue.IndexOf(Task);

            if (RemovedTaskIndex != -1)
            {
                TaskPriorityQueue.RemoveAt(RemovedTaskIndex);
            }
            else
            {
                Debug.LogWarning("RemoveTaskFromPriorityQueue for %s called, but it's not in the queue. Might have been already removed");
            }
        }
Beispiel #7
0
        public virtual void OnGameplayTaskDeactivated(UGameplayTask Task)
        {
            // cleanup after deactivation
            if (Task != ChildTask)
            {
                return;
            }

            Debug.LogWarning("%s> Child task deactivated: %s (state: %s)");
            if (Task.IsFinished())
            {
                ChildTask = null;
            }
        }
Beispiel #8
0
        public virtual void OnGameplayTaskDeactivated(UGameplayTask Task)
        {
            bool bIsFinished = Task.IsFinished();

            var childTask = Task.GetChildTask();

            if (childTask != null && bIsFinished)
            {
                if (Task.HasOwnerFinished())
                {
                    childTask.TaskOwnerEnded();
                }
                else
                {
                    childTask.EndTask();
                }
            }

            if (Task.IsTickingTask())
            {
                // If we are removing our last ticking task, set this component as inactive so it stops ticking
                TickingTasks.Remove(Task);
            }

            if (bIsFinished)
            {
                // using RemoveSwap rather than RemoveSingleSwap since a Task can be added
                // to KnownTasks both when activating as well as unpausing
                // while removal happens only once. It's cheaper to handle it here.
                KnownTasks.Remove(Task);
            }

            // Resource-using task
            if (Task.RequiresPriorityOrResourceManagement() && bIsFinished)
            {
                OnTaskEnded(Task);
            }

            if (!Task.IsOwnedByTasksComponent() && !Task.HasOwnerFinished())
            {
                var TaskOwner = Task.GetTaskOwner();
                TaskOwner.OnGameplayTaskDeactivated(Task);
            }

            UpdateShouldTick();
        }
Beispiel #9
0
        //处理 优先级 和 资源
        /// <summary>
        /// 处理传入的task, 如果本task没有优先级或者资源依赖就不处理
        /// </summary>
        public void AddTaskReadyForActivation(UGameplayTask NewTask)
        {
            if (!NewTask.RequiresPriorityOrResourceManagement())
            {
                return;
            }

            var e = new FGameplayTaskEventData(EGameplayTaskEvent.Add, NewTask);

            TaskEvents.Add(e);

            // trigger the actual processing only if it was the first event added to the list
            if (TaskEvents.Count == 1 && CanProcessEvents())
            {
                ProcessTaskEvents();
            }
        }
Beispiel #10
0
 public virtual void OnGameplayTaskInitialized(UGameplayTask Task)
 {
 }
Beispiel #11
0
 public virtual CUnitEntity GetGameplayTaskAvatar(UGameplayTask Task)
 {
     return(Task.GetAvatarActor());
 }
Beispiel #12
0
 public virtual CUnitEntity GetGameplayTaskOwner(UGameplayTask Task)
 {
     return(Task.GetOwnerActor());
 }
Beispiel #13
0
 // BEGIN IGameplayTaskOwnerInterface
 public virtual UGameplayTasksComponent GetGameplayTasksComponent(UGameplayTask Task)
 {
     return(this);
 }
Beispiel #14
0
 public FGameplayTaskEventData(EGameplayTaskEvent InEvent, UGameplayTask InRelatedTask)
 {
     Event       = InEvent;
     RelatedTask = InRelatedTask;
 }
Beispiel #15
0
 public virtual void OnGameplayTaskActivated(UGameplayTask Task)
 {
 }
Beispiel #16
0
 public virtual CUnitEntity GetGameplayTaskAvatar(UGameplayTask Task)
 {
     return(((Task == ChildTask) || (Task == this)) ? GetAvatarActor() : null);
 }