初始提交: UE5.3项目基础框架
This commit is contained in:
5
Source/BXSSP/Private/MainHUD.cpp
Normal file
5
Source/BXSSP/Private/MainHUD.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "MainHUD.h"
|
||||
|
||||
1073
Source/BXSSP/Private/Rover.cpp
Normal file
1073
Source/BXSSP/Private/Rover.cpp
Normal file
File diff suppressed because it is too large
Load Diff
99
Source/BXSSP/Private/RoverController.cpp
Normal file
99
Source/BXSSP/Private/RoverController.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "RoverController.h"
|
||||
#include "Rover.h"
|
||||
#include "RoverGameModeBase.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Kismet/KismetMathLibrary.h"
|
||||
|
||||
ARoverController* ARoverController::PlayerController = nullptr;
|
||||
|
||||
ARoverController::ARoverController()
|
||||
{
|
||||
PlayerController = this;
|
||||
}
|
||||
void ARoverController::BeginPlay()
|
||||
{
|
||||
|
||||
Super::BeginPlay();
|
||||
ARoverGameModeBase::Init();
|
||||
if (UGameplayStatics::GetPlayerController(GetWorld(), 0) == this) {
|
||||
|
||||
SetShowMouseCursor(true);
|
||||
Rover = Cast<ARover>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
|
||||
|
||||
UE_LOG(LogTemp, Log, TEXT("Init Successful"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ARoverController::SetMouseShowStatus(bool bStatus)
|
||||
{
|
||||
if (bStatus) {
|
||||
GetWorldTimerManager().ClearTimer(ResetMousePositionTimer);
|
||||
}
|
||||
else {
|
||||
GetMousePosition(ClickMousePosition.X, ClickMousePosition.Y);
|
||||
GetWorldTimerManager().ClearTimer(ResetMousePositionTimer);
|
||||
GetWorldTimerManager().SetTimer(ResetMousePositionTimer, this, &ARoverController::ResetMousePositionToClickPoint, 0.05f, true);
|
||||
}
|
||||
SetShowMouseCursor(bStatus);
|
||||
}
|
||||
|
||||
bool ARoverController::GetUnderMouseHitPosition(FHitResult& HitResult)
|
||||
{
|
||||
FVector2D MousePosition;
|
||||
GetMousePosition(MousePosition.X, MousePosition.Y);
|
||||
return GetUnderScreenHitPosition(MousePosition, HitResult);
|
||||
}
|
||||
|
||||
bool ARoverController::GetUnderScreenHitPosition(const FVector2D& ScreenPosition, FHitResult& HitResult)
|
||||
{
|
||||
FVector WorldLocation;
|
||||
FVector WorldDirection;
|
||||
DeprojectScreenPositionToWorld(ScreenPosition.X, ScreenPosition.Y, WorldLocation, WorldDirection);
|
||||
FVector End = WorldLocation + WorldDirection * 10000000000;
|
||||
if (GetWorld()->LineTraceSingleByChannel(HitResult, WorldLocation, End, ECollisionChannel::ECC_Visibility)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ARoverController::GetUnderscreenCenterHitPosition(FHitResult& HitResult)
|
||||
{
|
||||
FVector WorldLocation;
|
||||
FVector WorldDirection;
|
||||
FVector2D ScreenCenter = GetScreenCenterPosition();
|
||||
DeprojectScreenPositionToWorld(ScreenCenter.X, ScreenCenter.Y, WorldLocation, WorldDirection);
|
||||
FVector End = WorldLocation + WorldDirection * 10000000000;
|
||||
if (GetWorld()->LineTraceSingleByChannel(HitResult, WorldLocation, End, ECollisionChannel::ECC_Visibility)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
FVector2D ARoverController::GetScreenCenterPosition()
|
||||
{
|
||||
FVector2D ScreenCenter;
|
||||
GEngine->GameViewport->GetViewportSize(ScreenCenter);
|
||||
ScreenCenter *= 0.5;
|
||||
return ScreenCenter;
|
||||
}
|
||||
|
||||
|
||||
void ARoverController::ResetMousePositionToClickPoint()
|
||||
{
|
||||
SetMouseLocation(ClickMousePosition.X, ClickMousePosition.Y);
|
||||
}
|
||||
|
||||
void ARoverController::RotateCameraToTargetPoint(FRotator Rotation)
|
||||
{
|
||||
FRotator SelfRotation = GetControlRotation();
|
||||
if (UKismetMathLibrary::Dot_VectorVector(SelfRotation.Vector(), Rotation.Vector()) >= 0.999999) {
|
||||
SetControlRotation(Rotation);
|
||||
Rover->UpdatascreenCenterPointLocation();
|
||||
GetWorldTimerManager().ClearTimer(RotateCameraTimer);
|
||||
return;
|
||||
}
|
||||
SetControlRotation(UKismetMathLibrary::RInterpTo(SelfRotation, Rotation, GetWorld()->GetDeltaSeconds(), 5.f));
|
||||
}
|
||||
15
Source/BXSSP/Private/RoverGameModeBase.cpp
Normal file
15
Source/BXSSP/Private/RoverGameModeBase.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "RoverGameModeBase.h"
|
||||
|
||||
ARoverGameModeBase* ARoverGameModeBase::BaseGameMode = nullptr;
|
||||
|
||||
ARoverGameModeBase::ARoverGameModeBase()
|
||||
{
|
||||
BaseGameMode = this;
|
||||
}
|
||||
|
||||
void ARoverGameModeBase::Init()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user