feat: 新建CameraPawn类

This commit is contained in:
meishibiezb
2026-03-15 12:43:39 +08:00
parent 5d2c3534cc
commit 166198c3e3
5 changed files with 132 additions and 32 deletions

View File

@@ -0,0 +1,55 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "CameraPawn.h"
#include "GameFramework/SpringArmComponent.h"
#include "Camera/CameraComponent.h"
void ACameraPawn::CameraZoom(const FInputActionValue& Value)
{
}
void ACameraPawn::CameraRotate(const FInputActionValue& Value)
{
}
void ACameraPawn::CameraMove(const FInputActionValue& Value)
{
}
// Sets default values
ACameraPawn::ACameraPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
SpringArmComponent->SetupAttachment(RootComponent);
SpringArmComponent->TargetArmLength = 300.f;
SpringArmComponent->bUsePawnControlRotation = true;
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
}
// Called when the game starts or when spawned
void ACameraPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ACameraPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ACameraPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}

View File

@@ -0,0 +1,41 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "CameraPawn.generated.h"
UCLASS()
class LONESE_API ACameraPawn : public APawn
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
class USpringArmComponent* SpringArmComponent;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
class UCameraComponent* CameraComponent;
UFUNCTION(BlueprintCallable, Category = "Camera")
void CameraZoom(const FInputActionValue& Value);
UFUNCTION(BlueprintCallable, Category = "Camera")
void CameraRotate(const FInputActionValue& Value);
UFUNCTION(BlueprintCallable, Category = "Camera")
void CameraMove(const FInputActionValue& Value);
// Sets default values for this pawn's properties
ACameraPawn();
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
private:
};

View File

@@ -7,6 +7,8 @@
#include "EnhancedInputComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "CameraPawn.h"
void AMyCharacter::Move(const FInputActionValue& Value)
{
auto f2d = Value.Get<FVector2D>();

View File

@@ -21,6 +21,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
class UInputAction* CrouchAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
class ACameraPawn* CameraActor;
UFUNCTION(BlueprintCallable, Category = "Move")
void Move(const FInputActionValue& Value);
UFUNCTION(BlueprintCallable, Category = "Move")

View File

@@ -1,34 +1,33 @@
{
"FileVersion": 3,
"EngineAssociation": "5.7",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "lonese",
"Type": "Runtime",
"LoadingPhase": "Default"
}
],
"Plugins": [
{
"Name": "ModelingToolsEditorMode",
"Enabled": true
},
{
"Name": "Text3D",
"Enabled": true
},
{
"Name": "VisualStudioTools",
"Enabled": true,
"SupportedTargetPlatforms": [
"Win64"
]
}
],
"TargetPlatforms": [],
"AdditionalRootDirectories": [],
"AdditionalPluginDirectories": [],
"EpicSampleNameHash": ""
"FileVersion": 3,
"EngineAssociation": "5.7",
"Category": "",
"Description": "",
"Modules": [
{
"Name": "lonese",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine"
]
}
],
"Plugins": [
{
"Name": "ModelingToolsEditorMode",
"Enabled": true
},
{
"Name": "Text3D",
"Enabled": true
},
{
"Name": "VisualStudioTools",
"Enabled": true,
"SupportedTargetPlatforms": [
"Win64"
]
}
]
}