/// <summary> /// 一般 task自己会调用此方法 /// TODO 注意, 在调用本方法之前, 需要派发"on completed" delegates /// </summary> public void EndTask() { if (IsFinished()) { return; } TaskState = EGameplayTaskState.Finished; }
public UGameplayTask() { bTickingTask = false; bOwnedByTasksComponent = false; bClaimRequiredResources = true; bOwnerFinished = false; TaskState = EGameplayTaskState.Uninitialized; ResourceOverlapPolicy = ETaskResourceOverlapPolicy.StartOnTop; Priority = FGameplayTaskPriority.DefaultPriority; }
/// <summary> /// 如果owner "ended", 那么本方法会被调用. 在OnDestroy中调用 /// </summary> public void TaskOwnerEnded() { if (IsFinished()) { return; } bOwnerFinished = true; // mark as finished, just to be on the safe side TaskState = EGameplayTaskState.Finished; }
/// <summary> /// 激活任务的入口 /// </summary> private void PerformActivation() { if (IsActive()) { return; } TaskState = EGameplayTaskState.Active; Activate(); //有些立即完成的任务, 激活即完成 //如果没完成, 我们才跟component打交道 if (IsFinished() == false) { TasksComponent.OnGameplayTaskActivated(this); } }
/// <summary> /// 初始化任务, 但不激活. 激活需要调用Activate方法 /// </summary> public void InitTask(IGameplayTaskOwnerInterface InTaskOwner, int InPriority) { //Priority = InPriority; TaskOwner = InTaskOwner; TaskState = EGameplayTaskState.AwaitingActivation; if (bClaimRequiredResources) { ClaimedResources.AddSet(RequiredResources); } InTaskOwner.OnGameplayTaskInitialized(this); TasksComponent = InTaskOwner.GetGameplayTasksComponent(this); bOwnedByTasksComponent = (TaskOwner == TasksComponent); //避免两次调用OnGameplayTaskInitialized方法 if (!bOwnedByTasksComponent) { TasksComponent.OnGameplayTaskInitialized(this); } }
public static string GetTaskStateName(EGameplayTaskState Value) { return(""); }
protected virtual void Resume() { TaskState = EGameplayTaskState.Active; TasksComponent.OnGameplayTaskActivated(this); }
// protected by design. Not meant to be called outside from GameplayTaskComponent mechanics protected virtual void Pause() { TaskState = EGameplayTaskState.Paused; TasksComponent.OnGameplayTaskDeactivated(this); }
/* End and CleanUp the task - may be called by the task itself or by the task owner if the owner is ending. * IMPORTANT! Do NOT call directly! Call EndTask() or TaskOwnerEnded() * IMPORTANT! When overriding this function make sure to call Super.OnDestroy(bOwnerFinished) as the last thing, * since the function internally marks the task as "Pending Kill", and this may interfere with internal BP mechanics */ protected virtual void OnDestroy(bool bInOwnerFinished) { TaskState = EGameplayTaskState.Finished; TasksComponent.OnGameplayTaskDeactivated(this); }