From 3f4cdf5bfacd66111589a0b57b3343457d1f9e65 Mon Sep 17 00:00:00 2001 From: MARCEL HARA Date: Mon, 23 Jan 2023 16:14:15 +0000 Subject: [PATCH] Updated Interaction.cpp Optimized some functions and variables by storing them in beginplay --- Content/Levels/MerchantPrototype.umap | 4 ++-- .../MerchantInteraction/Interaction.cpp | 23 ++++++++----------- .../MerchantInteraction/Interaction.h | 18 ++++++++++++--- .../PlayerTemp/TempCharacter.h | 2 ++ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Content/Levels/MerchantPrototype.umap b/Content/Levels/MerchantPrototype.umap index d648c7a..da545bd 100644 --- a/Content/Levels/MerchantPrototype.umap +++ b/Content/Levels/MerchantPrototype.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ebb8b1c4142831775542c0bcb3400dc138a3360ffe820dd74cd460af4b914a53 -size 26504 +oid sha256:5efb970894cb114a37a45fac46558718d0fa4bfed2b9900eebd2a752fc71d021 +size 26607 diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp index 192d23c..f8a95f4 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.cpp @@ -22,7 +22,10 @@ AInteraction::AInteraction() void AInteraction::BeginPlay() { Super::BeginPlay(); - + TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); + MainCamera = Cast(TempCharacter->FindComponentByClass()); + TargetHealingLocation = HealingItem->GetActorLocation(); + TargetBuffLocation = BuffItem->GetActorLocation(); } // Called every frame @@ -80,8 +83,6 @@ void AInteraction::RemoveWidget() void AInteraction::CameraLeftMover() { UE_LOG(LogTemp, Display, TEXT("Button Left is being pressed")); - TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); - MainCamera = Cast(TempCharacter->FindComponentByClass()); if (TempCharacter == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); @@ -90,16 +91,15 @@ void AInteraction::CameraLeftMover() else { UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); - if (MainCamera == nullptr) + if (MainCamera == nullptr || HealingItem == nullptr) { UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); return; } else { - FVector TargetLocation = FVector(5700,-1270,4040); - FVector CameraLocation = MainCamera->GetComponentLocation(); - FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); + CameraLocation = MainCamera->GetComponentLocation(); + FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetHealingLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); } @@ -109,8 +109,6 @@ void AInteraction::CameraLeftMover() void AInteraction::CameraRightMover() { UE_LOG(LogTemp, Display, TEXT("Button Right is being pressed")); - TempCharacter = GetWorld()->GetFirstPlayerController()->GetCharacter(); - MainCamera = Cast(TempCharacter->FindComponentByClass()); if (TempCharacter == nullptr) { UE_LOG(LogTemp, Display, TEXT("Character not found in Interaction.cpp")); @@ -119,16 +117,15 @@ void AInteraction::CameraRightMover() else { UE_LOG(LogTemp, Display, TEXT("Character Found in interaction.cpp")); - if (MainCamera == nullptr) + if (MainCamera == nullptr || BuffItem == nullptr) { UE_LOG(LogTemp, Display, TEXT("Camera not found in Interaction.cpp")); return; } else { - FVector TargetLocation = FVector(5260, -840, 4070); - FVector CameraLocation = MainCamera->GetComponentLocation(); - FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetLocation); + CameraLocation = MainCamera->GetComponentLocation(); + FRotator CameraRotation = UKismetMathLibrary::FindLookAtRotation(CameraLocation, TargetBuffLocation); MainCamera->SetWorldRotation(CameraRotation); MainCamera->SetFieldOfView(40); } diff --git a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h index fb771a9..09e9478 100644 --- a/Source/the_twilight_abyss/MerchantInteraction/Interaction.h +++ b/Source/the_twilight_abyss/MerchantInteraction/Interaction.h @@ -24,10 +24,10 @@ public: // Called every frame virtual void Tick(float DeltaTime) override; - UPROPERTY(EditAnywhere) + UPROPERTY(EditAnywhere, Category= "Widgets") TSubclassOf ShopDialog; - UPROPERTY(EditAnywhere) + UPROPERTY(EditAnywhere, Category= "Widgets") TSubclassOf ItemSelector; virtual void OnInteract(); @@ -40,7 +40,7 @@ public: UPROPERTY() UUserWidget* ItemSelectorWidget; - UPROPERTY(EditAnywhere) + UPROPERTY(EditAnywhere, Category= "Widgets") float WaitTimer = 8.0f; UPROPERTY() @@ -60,5 +60,17 @@ public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player") ACharacter* TempCharacter; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items") + AActor* HealingItem; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Items") + AActor* BuffItem; + +private: + + FVector TargetHealingLocation; + FVector TargetBuffLocation; + FVector CameraLocation; }; diff --git a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h index 052239c..51c6394 100644 --- a/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h +++ b/Source/the_twilight_abyss/PlayerTemp/TempCharacter.h @@ -43,6 +43,8 @@ public: void InputDisabler(); void LineTraceLogic(); + + UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Health") float Health;