Initial commit
This commit is contained in:
118
Source/Aura/Private/Player/AuraPlayerController.cpp
Normal file
118
Source/Aura/Private/Player/AuraPlayerController.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
// Copyright Echo Devgroup
|
||||
|
||||
|
||||
#include "Player/AuraPlayerController.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "Interact/EnemyInterface.h"
|
||||
|
||||
AAuraPlayerController::AAuraPlayerController()
|
||||
{
|
||||
bReplicates = true;
|
||||
}
|
||||
|
||||
void AAuraPlayerController::PlayerTick(float DeltaTime)
|
||||
{
|
||||
Super::PlayerTick(DeltaTime);
|
||||
|
||||
CursorTrace();
|
||||
}
|
||||
|
||||
void AAuraPlayerController::CursorTrace()
|
||||
{
|
||||
FHitResult CursorHit;
|
||||
GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
|
||||
if (!CursorHit.bBlockingHit) return;
|
||||
|
||||
LastActor = ThisActor;
|
||||
ThisActor = CursorHit.GetActor();
|
||||
|
||||
/**
|
||||
*Line trace from curso. There are several scenarios
|
||||
* A. LastActor is null && ThisActor is null
|
||||
* - Do nothing
|
||||
* B. LastActor is null && ThisActor is valid
|
||||
* - Highlight ThisActor
|
||||
* C. LastActor is valid && ThisActor is null
|
||||
* - UnHighlight LastActor
|
||||
* D. LastAcrot is valid && ThisActor is valid but not equal
|
||||
* - UnHighligh LastActor
|
||||
* - Highlight ThisActor
|
||||
* E. LastActor is same as ThisActor
|
||||
* - Do Nothing
|
||||
*/
|
||||
|
||||
if (LastActor == nullptr)
|
||||
{
|
||||
if (ThisActor != nullptr)
|
||||
{
|
||||
//Case B
|
||||
ThisActor->HighlightActor();
|
||||
//UE_LOG(LogTemp, Warning, TEXT("Case B"));
|
||||
}
|
||||
}
|
||||
else //LastActor is Valid
|
||||
{
|
||||
if (ThisActor == nullptr)
|
||||
{
|
||||
LastActor->UnHighlightActor();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LastActor != ThisActor) // Case D
|
||||
{
|
||||
LastActor->UnHighlightActor();
|
||||
ThisActor->HighlightActor();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
check(AuraContext);
|
||||
|
||||
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
||||
if (Subsystem)
|
||||
{
|
||||
Subsystem->AddMappingContext(AuraContext,0);
|
||||
}
|
||||
|
||||
bShowMouseCursor = true;
|
||||
DefaultMouseCursor = EMouseCursor::Default;
|
||||
|
||||
FInputModeGameAndUI InputModeData;
|
||||
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
||||
InputModeData.SetHideCursorDuringCapture(false);
|
||||
SetInputMode(InputModeData);
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
|
||||
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent);
|
||||
|
||||
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
|
||||
{
|
||||
const FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
|
||||
const FRotator Rotation = GetControlRotation();
|
||||
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
|
||||
|
||||
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
|
||||
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
|
||||
|
||||
if (APawn* ControlledPawn = GetPawn<APawn>())
|
||||
{
|
||||
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
|
||||
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
|
||||
}
|
||||
}
|
||||
35
Source/Aura/Private/Player/AuraPlayerState.cpp
Normal file
35
Source/Aura/Private/Player/AuraPlayerState.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright Echo Devgroup
|
||||
|
||||
|
||||
#include "Player/AuraPlayerState.h"
|
||||
|
||||
#include "AbilitySystem/AuraAbilitySystemComponent.h"
|
||||
#include "AbilitySystem/AuraAttributeSet.h"
|
||||
#include "Net/UnrealNetwork.h"
|
||||
|
||||
AAuraPlayerState::AAuraPlayerState()
|
||||
{
|
||||
AbilitySystemComponent = CreateDefaultSubobject<UAuraAbilitySystemComponent>("AbilitySystemComponent");
|
||||
AbilitySystemComponent->SetIsReplicated(true);
|
||||
AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
|
||||
|
||||
AttributeSet = CreateDefaultSubobject<UAuraAttributeSet>("AttributeSet");
|
||||
NetUpdateFrequency = 100.f;
|
||||
|
||||
}
|
||||
|
||||
void AAuraPlayerState::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const
|
||||
{
|
||||
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||
DOREPLIFETIME(AAuraPlayerState, Level);
|
||||
}
|
||||
|
||||
UAbilitySystemComponent* AAuraPlayerState::GetAbilitySystemComponent() const
|
||||
{
|
||||
return AbilitySystemComponent;
|
||||
}
|
||||
|
||||
void AAuraPlayerState::OnRep_Level(int32 OldLevel)
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user