feat: 增加一些配置项
This commit is contained in:
@@ -10,14 +10,14 @@
|
|||||||
void ACameraPawn::CameraZoom(const FInputActionValue& Value)
|
void ACameraPawn::CameraZoom(const FInputActionValue& Value)
|
||||||
{
|
{
|
||||||
auto f = Value.Get<float>();
|
auto f = Value.Get<float>();
|
||||||
SpringArmComponent->TargetArmLength += f * 10.0f;
|
SpringArmComponent->TargetArmLength += f * ZoomSpeed;
|
||||||
SpringArmComponent->TargetArmLength = FMath::Clamp(SpringArmComponent->TargetArmLength, 300.0f, 3000.0f);
|
SpringArmComponent->TargetArmLength = FMath::Clamp(SpringArmComponent->TargetArmLength, MinArmLength, MaxArmLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACameraPawn::CameraRotate(const FInputActionValue& Value)
|
void ACameraPawn::CameraRotate(const FInputActionValue& Value)
|
||||||
{
|
{
|
||||||
auto f = Value.Get<float>();
|
auto f = Value.Get<float>();
|
||||||
FRotator r = FRotator(0.0f, f * 2.0f, 0.0f);
|
FRotator r = FRotator(0.0f, f * RotateSpeed, 0.0f);
|
||||||
AddActorWorldRotation(r);
|
AddActorWorldRotation(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,12 +27,12 @@ void ACameraPawn::CameraMove(const FInputActionValue& Value)
|
|||||||
auto r = GetActorRightVector();
|
auto r = GetActorRightVector();
|
||||||
auto f = r.Cross(FVector::UpVector);
|
auto f = r.Cross(FVector::UpVector);
|
||||||
f.Normalize();
|
f.Normalize();
|
||||||
SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f);
|
SetActorLocation(GetActorLocation() + f * f2d.X * MoveSpeed + r * f2d.Y * MoveSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACameraPawn::CameraReset(const FInputActionValue& Value)
|
void ACameraPawn::CameraReset(const FInputActionValue& Value)
|
||||||
{
|
{
|
||||||
SpringArmComponent->TargetArmLength = 1200.0f;
|
SpringArmComponent->TargetArmLength = InitialArmLength;
|
||||||
SetActorRotation(InitialRotation);
|
SetActorRotation(InitialRotation);
|
||||||
SetActorRelativeLocation(FVector::ZeroVector);
|
SetActorRelativeLocation(FVector::ZeroVector);
|
||||||
}
|
}
|
||||||
@@ -46,8 +46,8 @@ ACameraPawn::ACameraPawn()
|
|||||||
// 初始化 SpringArmComponent 和 CameraComponent
|
// 初始化 SpringArmComponent 和 CameraComponent
|
||||||
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
|
SpringArmComponent = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComponent"));
|
||||||
SpringArmComponent->SetupAttachment(RootComponent);
|
SpringArmComponent->SetupAttachment(RootComponent);
|
||||||
SpringArmComponent->TargetArmLength = 1200.f;
|
SpringArmComponent->TargetArmLength = InitialArmLength;
|
||||||
SpringArmComponent->bUsePawnControlRotation = true;
|
SpringArmComponent->bUsePawnControlRotation = true;// TODO: 何意味?
|
||||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||||
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
|
CameraComponent->SetupAttachment(SpringArmComponent, USpringArmComponent::SocketName);
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,23 @@ public:
|
|||||||
class USpringArmComponent* SpringArmComponent;
|
class USpringArmComponent* SpringArmComponent;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
||||||
class UCameraComponent* CameraComponent;
|
class UCameraComponent* CameraComponent;
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
|
UPROPERTY(VisibleInstanceOnly, BlueprintReadOnly, Category = "Camera")
|
||||||
APawn* FollowTarget;
|
APawn* FollowTarget;
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera")
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
FRotator InitialRotation = FRotator(-60.0f, 0.0f, 0.0f);
|
FRotator InitialRotation = FRotator(-60.0f, 0.0f, 0.0f);
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float InitialArmLength = 1200.0f;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float RotateSpeed = 2.0f;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float ZoomSpeed =10.0f;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float MoveSpeed = 10.0f;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float MaxArmLength = 3000.0f;
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Config")
|
||||||
|
float MinArmLength = 300.0f;
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable, Category = "Camera")
|
UFUNCTION(BlueprintCallable, Category = "Camera")
|
||||||
void CameraZoom(const FInputActionValue& Value);
|
void CameraZoom(const FInputActionValue& Value);
|
||||||
|
|||||||
Reference in New Issue
Block a user