From 7ef3265886acc1fa54ce9a6576d63374f01cb7b0 Mon Sep 17 00:00:00 2001 From: charnet3d Date: Tue, 27 Jun 2023 17:49:58 +0100 Subject: [PATCH] Section 10: Outline and Glow Effects - Lecture 169 Inventory Slot Widget --- .../_Game/Curves/MaterialInterpCurve.uasset | 3 ++ Content/_Game/Maps/DefaultMap.umap | 4 +-- .../SMGMaterials/M_SMG_Mat_Inst.uasset | 4 +-- .../Weapons/BaseWeapon/BaseWeaponBP.uasset | 4 +-- Source/Shooter/Item.cpp | 31 ++++++++++++++----- Source/Shooter/Item.h | 4 +++ Source/Shooter/ShooterCharacter.cpp | 2 +- 7 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 Content/_Game/Curves/MaterialInterpCurve.uasset diff --git a/Content/_Game/Curves/MaterialInterpCurve.uasset b/Content/_Game/Curves/MaterialInterpCurve.uasset new file mode 100644 index 00000000..eab2ff80 --- /dev/null +++ b/Content/_Game/Curves/MaterialInterpCurve.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:730c145032e2661eb2dc6a56bc3043bb4692977be417b26099f358e875291856 +size 2605 diff --git a/Content/_Game/Maps/DefaultMap.umap b/Content/_Game/Maps/DefaultMap.umap index 38cd464d..b5fefeb5 100644 --- a/Content/_Game/Maps/DefaultMap.umap +++ b/Content/_Game/Maps/DefaultMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:761a1383f0c734fe1848c4f7eee24936f56aa91447cbc53d51ec4892e792768f -size 97937 +oid sha256:074772a746368b9eabc6ff2bd5f9b156a50a031ee06934d613a1cf4501c7c907 +size 98354 diff --git a/Content/_Game/Materials/SMGMaterials/M_SMG_Mat_Inst.uasset b/Content/_Game/Materials/SMGMaterials/M_SMG_Mat_Inst.uasset index b1c08a44..ebb3c6e4 100644 --- a/Content/_Game/Materials/SMGMaterials/M_SMG_Mat_Inst.uasset +++ b/Content/_Game/Materials/SMGMaterials/M_SMG_Mat_Inst.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:392bedc57eb696120a1420760af330afba45c5bfabf82bb84cd02797a398d46c -size 23085 +oid sha256:9fbbb158174438126b23e8ad3612a65b1978f9f57783902b9b08da8c66d3c06e +size 22268 diff --git a/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset b/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset index 3e2c3723..dade3f9e 100644 --- a/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset +++ b/Content/_Game/Weapons/BaseWeapon/BaseWeaponBP.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1ea69c8a68479d7792f1b2e75405aac7d620901a5a8a073a0bea58fcb03d4dd0 -size 53632 +oid sha256:ce63d4716946991323e25b20dacfde54cc356d20f3fbde443c9b9dd60d933360 +size 53201 diff --git a/Source/Shooter/Item.cpp b/Source/Shooter/Item.cpp index fdc20b52..f15055ad 100644 --- a/Source/Shooter/Item.cpp +++ b/Source/Shooter/Item.cpp @@ -162,13 +162,29 @@ void AItem::OnConstruction(const FTransform& Transform) void AItem::UpdatePulse() { - if (ItemState != EItemState::EIS_Pickup) return; - - const float ElapsedTime { GetWorldTimerManager().GetTimerElapsed(PulseTimer) }; - if (PulseCurve) - { - const FVector CurveValue{ PulseCurve->GetVectorValue(ElapsedTime) }; + float ElapsedTime{}; + FVector CurveValue{}; + switch (ItemState) + { + case EItemState::EIS_Pickup: + if (PulseCurve) + { + ElapsedTime = GetWorldTimerManager().GetTimerElapsed(PulseTimer); + CurveValue = PulseCurve->GetVectorValue(ElapsedTime); + } + break; + case EItemState::EIS_EquipInterping: + if (InterpPulseCurve) + { + ElapsedTime = GetWorldTimerManager().GetTimerElapsed(ItemInterpTimer); + CurveValue = InterpPulseCurve->GetVectorValue(ElapsedTime); + } + break; + } + + if (DynamicMaterialInstance) + { DynamicMaterialInstance->SetScalarParameterValue(TEXT("GlowAmount"), CurveValue.X * GlowAmount); DynamicMaterialInstance->SetScalarParameterValue(TEXT("FresnelExponent"), CurveValue.Y * FresnelExponent); DynamicMaterialInstance->SetScalarParameterValue(TEXT("FresnelReflectFraction"), CurveValue.Z * FresnelReflectFraction); @@ -434,6 +450,7 @@ void AItem::StartItemCurve(AShooterCharacter* Char) bInterping = true; SetItemState(EItemState::EIS_EquipInterping); + GetWorldTimerManager().ClearTimer(PulseTimer); GetWorldTimerManager().SetTimer(ItemInterpTimer, this, &AItem::FinishInterping, ZCurveTime); @@ -459,8 +476,8 @@ void AItem::FinishInterping() { // Subtract 1 from the Item Count of the interp location struct Character->IncrementInterpLocItemCount(InterpLocIndex, -1); - Character->GetPickupItem(this); + SetItemState(EItemState::EIS_PickedUp); } // Set scale back to normal SetActorScale3D(FVector(1.f)); diff --git a/Source/Shooter/Item.h b/Source/Shooter/Item.h index 256242a6..f169df86 100644 --- a/Source/Shooter/Item.h +++ b/Source/Shooter/Item.h @@ -213,6 +213,10 @@ private: /** Curve to drive the dynamic material parameters */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) UCurveVector* PulseCurve; + + /** Curve to drive the dynamic material parameters */ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Item Properties", meta = (AllowPrivateAccess = true)) + UCurveVector* InterpPulseCurve; FTimerHandle PulseTimer; diff --git a/Source/Shooter/ShooterCharacter.cpp b/Source/Shooter/ShooterCharacter.cpp index f93df1b2..1ee0479a 100644 --- a/Source/Shooter/ShooterCharacter.cpp +++ b/Source/Shooter/ShooterCharacter.cpp @@ -147,7 +147,7 @@ void AShooterCharacter::BeginPlay() CameraDefaultFOV = FollowCamera->FieldOfView; CameraCurrentFOV = CameraDefaultFOV; } - + // Spawn the default weapon and equip it EquipWeapon(SpawnDefaultWeapon());