コード例 #1
0
UAITask_MoveTo* UAITask_MoveTo::AIMoveTo(AAIController* Controller, FVector InGoalLocation, AActor* InGoalActor, float AcceptanceRadius, EAIOptionFlag::Type StopOnOverlap, EAIOptionFlag::Type AcceptPartialPath, bool bUsePathfinding, bool bLockAILogic)
{
	UAITask_MoveTo* MyTask = Controller ? UAITask::NewAITask<UAITask_MoveTo>(*Controller, EAITaskPriority::High) : nullptr;
	if (MyTask)
	{
		FAIMoveRequest MoveReq;
		if (InGoalActor)
		{
			MoveReq.SetGoalActor(InGoalActor);
		}
		else
		{
			MoveReq.SetGoalLocation(InGoalLocation);
		}

		MoveReq.SetAcceptanceRadius(AcceptanceRadius);
		MoveReq.SetReachTestIncludesAgentRadius(FAISystem::PickAIOption(StopOnOverlap, MoveReq.IsReachTestIncludingAgentRadius()));
		MoveReq.SetAllowPartialPath(FAISystem::PickAIOption(AcceptPartialPath, MoveReq.IsUsingPartialPaths()));
		MoveReq.SetUsePathfinding(bUsePathfinding);
		if (Controller)
		{
			MoveReq.SetNavigationFilter(Controller->GetDefaultNavigationFilterClass());
		}

		MyTask->SetUp(Controller, MoveReq);

		if (bLockAILogic)
		{
			MyTask->RequestAILogicLocking();
		}
	}

	return MyTask;
}
コード例 #2
0
void UAITask_MoveTo::Activate()
{
	Super::Activate();

	FAIMoveRequest MoveRequest = (MoveGoalActor != nullptr) ? FAIMoveRequest(MoveGoalActor) : FAIMoveRequest(RealGoalLocation);

	MoveRequest.SetAllowPartialPath(bShouldAcceptPartialPath)
		.SetAcceptanceRadius(MoveAcceptanceRadius)
		.SetStopOnOverlap(bShouldStopOnOverlap)
		.SetUsePathfinding(bShouldUsePathfinding);

	const EPathFollowingRequestResult::Type RequestResult = OwnerController->MoveTo(MoveRequest);

	switch (RequestResult)
	{
	case EPathFollowingRequestResult::Failed:
		{
			EndTask();
			OnRequestFailed.Broadcast();
		}
		break;
	case EPathFollowingRequestResult::AlreadyAtGoal:
		{
			EndTask();
			OnMoveFinished.Broadcast(EPathFollowingResult::Success);
		}
		break;
	case EPathFollowingRequestResult::RequestSuccessful:
		if (OwnerController->GetPathFollowingComponent())
		{
			MoveRequestID = OwnerController->GetPathFollowingComponent()->GetCurrentRequestId();
			OwnerController->GetPathFollowingComponent()->OnMoveFinished.AddUObject(this, &UAITask_MoveTo::HandleMoveFinished);
		}
		break;
	default:
		checkNoEntry();
		break;
	}
}