document.write("
// Fill out your copyright notice in the Description page of Project Settings. ADandelionPlayerCharacter::ADandelionPlayerCharacter() { SetupCameraBoom(); SetupCamera(); } void ADandelionPlayerCharacter::SetupCameraBoom() { CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->SetUsingAbsoluteRotation(true); // Don't want arm to rotate when character does CameraBoom->TargetArmLength = 800.f; CameraBoom->SetRelativeRotation(FRotator(-60.f, 0.f, 0.f)); CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level } void ADandelionPlayerCharacter::SetupCamera() { TopDownCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera")); TopDownCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm } void ADandelionPlayerCharacter::PossessedBy(AController* NewController) { Super::PossessedBy(NewController); InitAbilitySystem(); } void ADandelionPlayerCharacter::InitAbilitySystem() { ADandelionPlayerState* SelfPlayerState = GetPlayerState<ADandelionPlayerState>(); if (!ensure(IsValid(SelfPlayerState))) { UE_LOG( LogTemplateCharacter, Error, TEXT("%s: Attempted InitAbilitySystem with invalid PlayerState."), *GetFullNameSafe(this) ); return; } UAbilitySystemComponent* const AbilitySystemComponent = GetAbilitySystemComponent(); AbilitySystemComponent->InitAbilityActorInfo(SelfPlayerState, this); for (const UDandelionAbilitySet* GameplayAbilitySet : DefaultGameplayAbilitySets) { GameplayAbilitySet->GiveAbilities(GetAbilitySystemComponent(), InputActionGameplayAbilityMappings); } SelfPlayerState->InitAbilitySystem(); } void ADandelionPlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); UEnhancedInputComponent* EnhancedInputComponent = Cast<UEnhancedInputComponent>(PlayerInputComponent); if (!ensure(IsValid(EnhancedInputComponent))) { UE_LOG( LogTemplateCharacter, Error, TEXT("%s: Has a PlayerInputComponent that is not of type EnhancedInputComponent."), *GetFullNameSafe(this) ) return; } if (!IsValid(InputActionGameplayAbilityMappings)) { UE_LOG( LogTemplateCharacter, Warning, TEXT("%s: Does not have any InputActionGameplayAbilityMappings set."), *GetFullNameSafe(this) ) return; } for (const FInputActionGameplayAbilityMappingData& Mapping : InputActionGameplayAbilityMappings->GetMappings()) { if (!Mapping.IsValid()) { UE_LOG( LogTemplateCharacter, Warning, TEXT( "%s: Encountered an invalid mapping in InitAbilitySystem with InputAction: %s and GameplayAbility: %s." ), *GetFullNameSafe(this), *GetFullNameSafe(Mapping.InputAction), *GetFullNameSafe(Mapping.GameplayAbilityClass) ) continue; } const UInputAction* InputAction = Mapping.InputAction; const int32 InputID = Mapping.InputID; // TODO: Are these bindings dangling? switch (Mapping.TriggerType) { case ETriggerEvent::None: break; case ETriggerEvent::Triggered: { EnhancedInputComponent->BindAction( InputAction, ETriggerEvent::Triggered, this, &ThisClass::OnAbilityInputTriggered, InputID ); break; } case ETriggerEvent::Started: { EnhancedInputComponent->BindAction( InputAction, ETriggerEvent::Started, this, &ThisClass::OnAbilityInputTriggered, InputID ); break; } default: { UE_LOG( LogTemplateCharacter, Error, TEXT( "%s: Encountered an invalid TriggerType when processing FInputActionGameplayAbilityMappingData." ), *GetNameSafe(this) ) break; } } EnhancedInputComponent->BindAction( InputAction, ETriggerEvent::Completed, this, &ThisClass::OnAbilityInputCompleted, InputID ); } } void ADandelionPlayerCharacter::OnAbilityInputTriggered(const int32 InputID) { GetAbilitySystemComponent()->AbilityLocalInputPressed(InputID); } void ADandelionPlayerCharacter::OnAbilityInputCompleted(const int32 InputID) { GetAbilitySystemComponent()->AbilityLocalInputReleased(InputID); } UAbilitySystemComponent* ADandelionPlayerCharacter::GetAbilitySystemComponent() const { APlayerState* SelfPlayerState = GetPlayerState(); if (!IsValid(SelfPlayerState)) { UE_LOG(LogTemplateCharacter, Warning, TEXT("%s: Unable to retrieve PlayerState."), *GetFullNameSafe(this)); return nullptr; } const IAbilitySystemInterface* AbilitySystemInterface = Cast<IAbilitySystemInterface>(SelfPlayerState); if (!AbilitySystemInterface) { UE_LOG( LogTemplateCharacter, Warning, TEXT("%s: Character's PlayerState: %s does not implement IAbilitySystemInterface."), *GetFullNameSafe(this), *GetFullNameSafe(SelfPlayerState) ); return nullptr; } return AbilitySystemInterface->GetAbilitySystemComponent(); }