diff --git a/Content/Blueprints/BP_TestChar.uasset b/Content/Blueprints/BP_TestChar.uasset index 977aee5..5394a40 100644 --- a/Content/Blueprints/BP_TestChar.uasset +++ b/Content/Blueprints/BP_TestChar.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0c3315761dac78227246642dbfb87a57a1a6976937bb81d44e5c81e03d4ecb14 -size 35702 +oid sha256:ab7d4c80512e5a429f683b0d634b583f773e2dc13323d994aa5926546bc86be2 +size 35856 diff --git a/Content/Inputs/IA/IA_CameraResetAction.uasset b/Content/Inputs/IA/IA_CameraResetAction.uasset new file mode 100644 index 0000000..a96f720 --- /dev/null +++ b/Content/Inputs/IA/IA_CameraResetAction.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0263a683f43bdd8802b013ae6ec19f95b514b864fd40dd51b7d2596cb7d0db11 +size 1207 diff --git a/Content/Inputs/IMC/IMC_Context.uasset b/Content/Inputs/IMC/IMC_Context.uasset index 2050f5b..b98783e 100644 --- a/Content/Inputs/IMC/IMC_Context.uasset +++ b/Content/Inputs/IMC/IMC_Context.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:898c0e7ca1e164a68e000e7f8a71fd08db02d71d7d5214a02f2be27c974d4d03 -size 8630 +oid sha256:7ef8f106233c3145223035eedca1342073d242f3fd6d6bebf9d6cf919d4f11da +size 9108 diff --git a/Source/lonese/CameraPawn.cpp b/Source/lonese/CameraPawn.cpp index 76c06e1..9b49c80 100644 --- a/Source/lonese/CameraPawn.cpp +++ b/Source/lonese/CameraPawn.cpp @@ -27,6 +27,13 @@ void ACameraPawn::CameraMove(const FInputActionValue& Value) SetActorLocation(GetActorLocation() + f * f2d.X * 10.0f + r * f2d.Y * 10.0f); } +void ACameraPawn::CameraReset(const FInputActionValue& Value) +{ + SpringArmComponent->TargetArmLength = 1200.0f; + SetActorRotation(InitialRotation); + SetActorRelativeLocation(FVector::ZeroVector); +} + // Sets default values ACameraPawn::ACameraPawn() { @@ -61,7 +68,11 @@ void ACameraPawn::BeginPlay() // 附加到父物体 this->AttachToActor(FollowTarget, FAttachmentTransformRules::KeepWorldTransform); + } + + // 设置自身旋转 + SetActorRotation(InitialRotation); } // Called every frame diff --git a/Source/lonese/CameraPawn.h b/Source/lonese/CameraPawn.h index 9007742..0fcf1b9 100644 --- a/Source/lonese/CameraPawn.h +++ b/Source/lonese/CameraPawn.h @@ -18,6 +18,8 @@ public: class UCameraComponent* CameraComponent; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera") APawn* FollowTarget; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera") + FRotator InitialRotation = FRotator(-60.0f, 0.0f, 0.0f); UFUNCTION(BlueprintCallable, Category = "Camera") void CameraZoom(const FInputActionValue& Value); @@ -25,6 +27,8 @@ public: void CameraRotate(const FInputActionValue& Value); UFUNCTION(BlueprintCallable, Category = "Camera") void CameraMove(const FInputActionValue& Value); + UFUNCTION(BlueprintCallable, Category = "Camera") + void CameraReset(const FInputActionValue& Value); // Sets default values for this pawn's properties ACameraPawn(); diff --git a/Source/lonese/MyCharacter.cpp b/Source/lonese/MyCharacter.cpp index c3ebb7c..0684b96 100644 --- a/Source/lonese/MyCharacter.cpp +++ b/Source/lonese/MyCharacter.cpp @@ -69,6 +69,14 @@ void AMyCharacter::CameraZoom(const FInputActionValue& Value) } } +void AMyCharacter::CameraReset(const FInputActionValue& Value) +{ + if (CameraActor) + { + CameraActor->CameraReset(Value); + } +} + // Sets default values AMyCharacter::AMyCharacter() { @@ -98,7 +106,7 @@ void AMyCharacter::BeginPlay() } FTransform SpawnTransform(GetActorRotation(), GetActorLocation()); temp = w->SpawnActorDeferred(CameraClass, SpawnTransform); - temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f)); + /*temp->SetActorRotation(FRotator(-60.0f, 0.0f, 0.0f));*/ temp->FollowTarget = this; temp->FinishSpawning(SpawnTransform); } @@ -153,6 +161,10 @@ void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCompone { EnhancedInputComponent->BindAction(CameraZoomAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraZoom); } + if (CameraResetAction) + { + EnhancedInputComponent->BindAction(CameraResetAction, ETriggerEvent::Triggered, this, &AMyCharacter::CameraReset); + } } } diff --git a/Source/lonese/MyCharacter.h b/Source/lonese/MyCharacter.h index 8f7f053..fb0c4c2 100644 --- a/Source/lonese/MyCharacter.h +++ b/Source/lonese/MyCharacter.h @@ -24,6 +24,8 @@ public: class UInputAction* CameraMoveAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") class UInputAction* CameraZoomAction; + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input") + class UInputAction* CameraResetAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera") class TSubclassOf CameraActorClass; @@ -66,4 +68,5 @@ private: void CameraZoom(const FInputActionValue& Value); void CameraRotate(const FInputActionValue& Value); void CameraMove(const FInputActionValue& Value); + void CameraReset(const FInputActionValue& Value); };