/** 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); } }
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); } }
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); } } }
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; }
/// <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(); } }
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"); } }
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; } }
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(); }
//处理 优先级 和 资源 /// <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(); } }
public virtual void OnGameplayTaskInitialized(UGameplayTask Task) { }
public virtual CUnitEntity GetGameplayTaskAvatar(UGameplayTask Task) { return(Task.GetAvatarActor()); }
public virtual CUnitEntity GetGameplayTaskOwner(UGameplayTask Task) { return(Task.GetOwnerActor()); }
// BEGIN IGameplayTaskOwnerInterface public virtual UGameplayTasksComponent GetGameplayTasksComponent(UGameplayTask Task) { return(this); }
public FGameplayTaskEventData(EGameplayTaskEvent InEvent, UGameplayTask InRelatedTask) { Event = InEvent; RelatedTask = InRelatedTask; }
public virtual void OnGameplayTaskActivated(UGameplayTask Task) { }
public virtual CUnitEntity GetGameplayTaskAvatar(UGameplayTask Task) { return(((Task == ChildTask) || (Task == this)) ? GetAvatarActor() : null); }