コード例 #1
0
void FBehaviorTreeDebugger::OnInstanceSelectedInDropdown(UBehaviorTreeComponent* SelectedInstance)
{
	if (SelectedInstance)
	{
		ClearDebuggerState();

		AController* OldController = TreeInstance.IsValid() ? Cast<AController>(TreeInstance->GetOwner()) : NULL;
		APawn* OldPawn = OldController != NULL ? OldController->GetPawn() : NULL;
		USelection* SelectedActors = GEditor->GetSelectedActors();
		if (SelectedActors && OldPawn)
		{
			SelectedActors->Deselect(OldPawn);
		}

		TreeInstance = SelectedInstance;

		if (SelectedActors && GEditor && SelectedInstance && SelectedInstance->GetOwner())
		{
			AController* TestController = Cast<AController>(SelectedInstance->GetOwner());
			APawn* Pawn = TestController != NULL ? TestController->GetPawn() : NULL;
			if (Pawn)
			{
				SelectedActors = GEditor->GetSelectedActors();
				SelectedActors->Select(Pawn);
				AGameplayDebuggingReplicator::OnSelectionChangedDelegate.Broadcast(Pawn);
			}
		}

		Refresh();
	}
}
コード例 #2
0
ファイル: CheatManager.cpp プロジェクト: kidaa/UnrealEngineVR
void UCheatManager::ViewPlayer( const FString& S )
{
	AController* Controller = NULL;
	for( FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator )
	{
		Controller = *Iterator;
		if ( Controller->PlayerState && (FCString::Stricmp(*Controller->PlayerState->PlayerName, *S) == 0 ) )
		{
			break;
		}
	}

	if ( Controller && Controller->GetPawn() != NULL )
	{
		GetOuterAPlayerController()->ClientMessage(FText::Format(LOCTEXT("ViewPlayer", "Viewing from {0}"), FText::FromString(Controller->PlayerState->PlayerName)).ToString(), TEXT("Event"));
		GetOuterAPlayerController()->SetViewTarget(Controller->GetPawn());
	}
}
コード例 #3
0
const AActor* UAIPerceptionComponent::GetBodyActor() const
{
    AController* OwnerController = Cast<AController>(GetOuter());
    if (OwnerController != NULL)
    {
        return OwnerController->GetPawn();
    }

    return Cast<AActor>(GetOuter());
}
コード例 #4
0
AActor * AHunterProjectile::FindHitActor()
{
	const FVector &thisLocation = GetActorLocation();

	UFlockingDataCache *cache = UFlockingDataCache::GetCacheChecked(this);
	
	ACharacter *playerCharacter = nullptr;
	for (FConstControllerIterator It = GetWorld()->GetControllerIterator(); It; ++It)
	{
		AController *controller = *It;
		APawn *otherPawn = controller->GetPawn();
		if (otherPawn == nullptr)
		{
			continue;
		}

		if (controller->IsA(APlayerController::StaticClass()))
		{
			playerCharacter = Cast<ACharacter>(controller->GetPawn());
		}
	}
	
	const TArray<FVector> &calfLocations = cache->GetTeamData(TEAM_CALVES)->m_locations;
	const TArray<FVector> &playerLocations = cache->GetLocationsPlayer();

	int32 targetCalf = FindHitActor(calfLocations, cache->GetTeamData(TEAM_CALVES)->m_agentRadius * 0.5f);
	AActor *targetActor = nullptr;
	if (targetCalf == INDEX_NONE)
	{
		int32 targetPlayer = FindHitActor(playerLocations, 0.5f * playerCharacter->GetCapsuleComponent()->GetScaledCapsuleRadius());
		if (targetPlayer != INDEX_NONE)
		{
			targetActor = playerCharacter;
		}
	}
	else
	{
		targetActor = cache->GetOrCreateTeamData(TEAM_CALVES).m_agents[targetCalf];
	}
	
	return targetActor;
}
コード例 #5
0
void ANavLinkProxy::NotifySmartLinkReached(UNavLinkCustomComponent* LinkComp, UPathFollowingComponent* PathComp, const FVector& DestPoint)
{
	AActor* PathOwner = PathComp->GetOwner();
	AController* ControllerOwner = Cast<AController>(PathOwner);
	if (ControllerOwner)
	{
		PathOwner = ControllerOwner->GetPawn();
	}

	ReceiveSmartLinkReached(PathOwner, DestPoint);
	OnSmartLinkReached.Broadcast(PathOwner, DestPoint);
}
コード例 #6
0
ファイル: WeaponComponent.cpp プロジェクト: Janonard/Ambosia
AActor* UWeaponComponent::PlotHitLine(float LineLength, AController* Instigator, TSubclassOf<UDamageType> DamageType, UGameplaySystemComponent* GameplaySystem)
{
	if (this->GetOwner() == nullptr)
		return nullptr;
	AController* OwnerAsController = dynamic_cast<AController*>(this->GetOwner());
	if (OwnerAsController == nullptr)
		return nullptr;
	if (OwnerAsController->GetPawn() == nullptr)
		return nullptr;

	FVector TraceStart = OwnerAsController->GetPawn()->GetActorLocation();
	FVector TraceEnd = OwnerAsController->GetPawn()->GetActorLocation();
	{
		FRotator Rotation = OwnerAsController->GetControlRotation();
		TraceEnd += Rotation.RotateVector(FVector(LineLength, 0, 0));
	}

	// Setup the trace query  
	FCollisionQueryParams TraceParams = FCollisionQueryParams();
	TraceParams.AddIgnoredActor(OwnerAsController->GetPawn());
	TraceParams.bTraceAsyncScene = true;
	FCollisionResponseParams CollisionParams = FCollisionResponseParams();

	FHitResult HitResult;
	if (this->GetWorld()->LineTraceSingleByChannel(HitResult, TraceStart, TraceEnd, ECC_GameTraceChannel1, TraceParams, CollisionParams))
	{
		if (GameplaySystem == nullptr)
			return nullptr;
		APawn* TargetAsPawn = dynamic_cast<APawn*>(HitResult.Actor.Get());
		if (TargetAsPawn)
		{
			TargetAsPawn->GetController()->TakeDamage(GameplaySystem->GetInfightAttackPoints(), FDamageEvent(DamageType), Instigator, Instigator->GetPawn());
		}
		return HitResult.GetActor();
	}
	else
	{
		return nullptr;
	}
}
コード例 #7
0
void UPawnNoiseEmitterComponent::MakeNoise(AActor* NoiseMaker, float Loudness, const FVector& NoiseLocation)
{
	if (!NoiseMaker || Loudness <= 0.f)
	{
		return;
	}

	// Get the Pawn that owns us, either directly or through a possible Controller owner.
	AActor* Owner = GetOwner();
	APawn* PawnOwner = Cast<APawn>(Owner);
	if (PawnOwner == NULL)
	{
		AController* OwnerController = Cast<AController>(Owner);
		if (IsValid(OwnerController))
		{
			PawnOwner = OwnerController->GetPawn();
		}
	}

	// only emit sounds from pawns with controllers
	if (!IsValid(PawnOwner) || !PawnOwner->Controller)
	{
		return;
	}

	// Was this noise made locally by this pawn?
	if ( NoiseMaker == PawnOwner || ((PawnOwner->GetActorLocation() - NoiseLocation).SizeSquared() <= FMath::Square(PawnOwner->GetSimpleCollisionRadius())) )
	{
		// use loudest noise within NoiseLifetime
		// Do not reset volume to zero after time has elapsed; sensors detecting the sound can choose for themselves how long to care about sounds.
		const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastLocalNoiseTime) > NoiseLifetime;
		if (bNoiseExpired || Loudness >= LastLocalNoiseVolume)
		{
			LastLocalNoiseVolume = Loudness;
			LastLocalNoiseTime = GetWorld()->GetTimeSeconds();
		}
	}
	// noise is not local - use loudest in this period
	else
	{
		const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastRemoteNoiseTime) > NoiseLifetime;
		if (bNoiseExpired || Loudness >= LastRemoteNoiseVolume)
		{
			LastRemoteNoiseVolume = Loudness;
			LastRemoteNoisePosition = NoiseLocation;
			LastRemoteNoiseTime = GetWorld()->GetTimeSeconds();
		}
	}
}
コード例 #8
0
APawn* UPawnActionsComponent::CacheControlledPawn()
{
    if (ControlledPawn == NULL)
    {
        AActor* ActorOwner = GetOwner();
        if (ActorOwner)
        {
            ControlledPawn = Cast<APawn>(ActorOwner);
            if (ControlledPawn == NULL)
            {
                AController* Controller = Cast<AController>(ActorOwner);
                if (Controller != NULL)
                {
                    ControlledPawn = Controller->GetPawn();
                }
            }
        }
    }

    return ControlledPawn;
}
コード例 #9
0
void UPawnNoiseEmitterComponent::MakeNoise(AActor* NoiseMaker, float Loudness, const FVector& NoiseLocation)
{
    // @hack! this won't be needed once UPawnNoiseEmitterComponent gets moved to AIModule
    // there's no other way to easily and efficiently prevent infinite recursion when
    // bAIPerceptionSystemCompatibilityMode == true and UAISense_Hearing is not being used (yet)
    static bool bMakeNoiseLockHack = false;
    if (bMakeNoiseLockHack)
    {
        bMakeNoiseLockHack = false;
        return;
    }

    if (!NoiseMaker || Loudness <= 0.f)
    {
        return;
    }

    // Get the Pawn that owns us, either directly or through a possible Controller owner.
    AActor* Owner = GetOwner();
    APawn* PawnOwner = Cast<APawn>(Owner);
    if (PawnOwner == NULL)
    {
        AController* OwnerController = Cast<AController>(Owner);
        if (IsValid(OwnerController))
        {
            PawnOwner = OwnerController->GetPawn();
        }
    }

    // only emit sounds from pawns with controllers
    if (!PawnOwner || PawnOwner->IsPendingKill() || !PawnOwner->Controller)
    {
        return;
    }

    // Was this noise made locally by this pawn?
    if ( NoiseMaker == PawnOwner || ((PawnOwner->GetActorLocation() - NoiseLocation).SizeSquared() <= FMath::Square(PawnOwner->GetSimpleCollisionRadius())) )
    {
        // use loudest noise within NoiseLifetime
        // Do not reset volume to zero after time has elapsed; sensors detecting the sound can choose for themselves how long to care about sounds.
        const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastLocalNoiseTime) > NoiseLifetime;
        if (bNoiseExpired || Loudness >= LastLocalNoiseVolume)
        {
            LastLocalNoiseVolume = Loudness;
            LastLocalNoiseTime = GetWorld()->GetTimeSeconds();
        }
    }
    // noise is not local - use loudest in this period
    else
    {
        const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastRemoteNoiseTime) > NoiseLifetime;
        if (bNoiseExpired || Loudness >= LastRemoteNoiseVolume)
        {
            LastRemoteNoiseVolume = Loudness;
            LastRemoteNoisePosition = NoiseLocation;
            LastRemoteNoiseTime = GetWorld()->GetTimeSeconds();
        }
    }

    if (bAIPerceptionSystemCompatibilityMode)
    {
        bMakeNoiseLockHack = true;
        NoiseMaker->MakeNoise(Loudness, PawnOwner, NoiseLocation);
    }
}