feat: 新建CameraPawn类
This commit is contained in:
55
Source/lonese/CameraPawn.cpp
Normal file
55
Source/lonese/CameraPawn.cpp
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
41
Source/lonese/CameraPawn.h
Normal file
41
Source/lonese/CameraPawn.h
Normal 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:
|
||||||
|
|
||||||
|
};
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "EnhancedInputComponent.h"
|
#include "EnhancedInputComponent.h"
|
||||||
#include "GameFramework/CharacterMovementComponent.h"
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
|
|
||||||
|
#include "CameraPawn.h"
|
||||||
|
|
||||||
void AMyCharacter::Move(const FInputActionValue& Value)
|
void AMyCharacter::Move(const FInputActionValue& Value)
|
||||||
{
|
{
|
||||||
auto f2d = Value.Get<FVector2D>();
|
auto f2d = Value.Get<FVector2D>();
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public:
|
|||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||||
class UInputAction* CrouchAction;
|
class UInputAction* CrouchAction;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
|
class ACameraPawn* CameraActor;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
void Move(const FInputActionValue& Value);
|
void Move(const FInputActionValue& Value);
|
||||||
UFUNCTION(BlueprintCallable, Category = "Move")
|
UFUNCTION(BlueprintCallable, Category = "Move")
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
{
|
{
|
||||||
"Name": "lonese",
|
"Name": "lonese",
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "Default"
|
"LoadingPhase": "Default",
|
||||||
|
"AdditionalDependencies": [
|
||||||
|
"Engine"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Plugins": [
|
"Plugins": [
|
||||||
@@ -26,9 +29,5 @@
|
|||||||
"Win64"
|
"Win64"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"TargetPlatforms": [],
|
|
||||||
"AdditionalRootDirectories": [],
|
|
||||||
"AdditionalPluginDirectories": [],
|
|
||||||
"EpicSampleNameHash": ""
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user