1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| void AMyPlayerCtrler::SetupInputComponent() { Super::SetupInputComponent();
InputComponent->BindAction("LeftMouse", IE_Pressed, this, &AMyPlayerCtrler::OnLeftMousePressed); InputComponent->BindAction("RightMouse", IE_Pressed, this, &AMyPlayerCtrler::OnRightMousePressed);
InputComponent->BindAction("ReadyAtk", IE_Pressed, this, &AMyPlayerCtrler::OnReadAtk); }
void AMyPlayerCtrler::OnLeftMousePressed() { FVector2D pressPos; this->GetMousePosition(pressPos.X, pressPos.Y); UE_LOG(GameLogger, Warning, TEXT("--- AMyPlayerCtrler::OnLeftMousePressed, pos:%s"), *pressPos.ToString());
bool isAtk = false; FVector WorldPosition(0.f); AActor* const HitActor = GetClickTarget(pressPos, WorldPosition); AMyChar* tarChar = Cast<AMyChar>(HitActor); if (mSelectedVec.Num() > 0) { if (mIsReadyAtk) {
if (tarChar != nullptr) { AtkTarget(tarChar); } else { MoveDestination(WorldPosition); }
isAtk = true; mIsReadyAtk = false; } }
if (!isAtk) { TArray<AMyChar*> dstCharVec; if (tarChar != nullptr) { dstCharVec.Add(tarChar); } SetSelected(dstCharVec); }
}
void AMyPlayerCtrler::OnRightMousePressed() { FVector2D pressPos; this->GetMousePosition(pressPos.X, pressPos.Y); UE_LOG(GameLogger, Warning, TEXT("--- AMyPlayerCtrler::OnLeftMousePressed, pos:%s"), *pressPos.ToString());
FHitResult HitResult; this->GetHitResultAtScreenPosition(pressPos, CurrentClickTraceChannel, true, HitResult); if (HitResult.bBlockingHit) { MoveDestination(HitResult.ImpactPoint); } }
void AMyPlayerCtrler::OnReadAtk() { mIsReadyAtk = true; }
|