Use WeaponPickupTemplate when spawning WeaponPickup
This commit is contained in:
parent
d200298ea6
commit
7c0d00a4a5
Binary file not shown.
BIN
Content/Enemy/BP_WeaponPickupTemplate.uasset (Stored with Git LFS)
BIN
Content/Enemy/BP_WeaponPickupTemplate.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Enemy/BP_WeaponPickupWidget.uasset (Stored with Git LFS)
BIN
Content/Enemy/BP_WeaponPickupWidget.uasset (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
|
@ -123,9 +123,16 @@ void AEnemyAIController::OnDeath(FDamageInfo info)
|
||||||
if (enemy->DefaultWeaponInventory.Num() > 0)
|
if (enemy->DefaultWeaponInventory.Num() > 0)
|
||||||
{
|
{
|
||||||
// TODO: This can sometimes crash, need to investigate
|
// TODO: This can sometimes crash, need to investigate
|
||||||
if (auto weaponPickup = GetWorld()->SpawnActor<AWeaponPickup>())
|
if (auto weaponPickup = GetWorld()->SpawnActor<AWeaponPickup>(enemy->GetCurrentWeapon()->GetPickupTemplate()))
|
||||||
{
|
{
|
||||||
weaponPickup->SetActorLocation(enemy->GetActorLocation());
|
float radius;
|
||||||
|
float halfHeight;
|
||||||
|
enemy->GetCapsuleComponent()->GetScaledCapsuleSize(radius, halfHeight);
|
||||||
|
|
||||||
|
auto location = enemy->GetActorLocation();
|
||||||
|
location.Z -= halfHeight;
|
||||||
|
weaponPickup->SetActorLocation(location);
|
||||||
|
|
||||||
weaponPickup->SetWeapon(enemy->DefaultWeaponInventory[enemy->GetCurrentInventorySlot()]);
|
weaponPickup->SetWeapon(enemy->DefaultWeaponInventory[enemy->GetCurrentInventorySlot()]);
|
||||||
weaponPickup->SetWeaponProperties(*enemy->CurrentWeapon->GetWeaponProperties());
|
weaponPickup->SetWeaponProperties(*enemy->CurrentWeapon->GetWeaponProperties());
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,11 @@ UNiagaraSystem* AWeapon::GetImpactParticleSystem()
|
||||||
return ImpactParticleSystem;
|
return ImpactParticleSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TSubclassOf<AWeaponPickup> AWeapon::GetPickupTemplate()
|
||||||
|
{
|
||||||
|
return PickupTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
TSubclassOf<class ANakatomiFieldSystemActor> AWeapon::GetFieldSystemActor()
|
TSubclassOf<class ANakatomiFieldSystemActor> AWeapon::GetFieldSystemActor()
|
||||||
{
|
{
|
||||||
return FieldSystemActor;
|
return FieldSystemActor;
|
||||||
|
|
|
@ -59,6 +59,9 @@ protected:
|
||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
UNiagaraSystem* ImpactParticleSystem;
|
UNiagaraSystem* ImpactParticleSystem;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<class AWeaponPickup> PickupTemplate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this actor's properties
|
// Sets default values for this actor's properties
|
||||||
AWeapon();
|
AWeapon();
|
||||||
|
@ -108,4 +111,6 @@ public:
|
||||||
TSubclassOf<class ADecalActor> GetDecalActor();
|
TSubclassOf<class ADecalActor> GetDecalActor();
|
||||||
|
|
||||||
UNiagaraSystem* GetImpactParticleSystem();
|
UNiagaraSystem* GetImpactParticleSystem();
|
||||||
|
|
||||||
|
TSubclassOf<class AWeaponPickup> GetPickupTemplate();
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,10 +2,18 @@
|
||||||
|
|
||||||
#include "WeaponPickup.h"
|
#include "WeaponPickup.h"
|
||||||
#include "PlayerCharacter.h"
|
#include "PlayerCharacter.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Kismet/KismetMathLibrary.h"
|
||||||
|
#include "UI/WeaponPickupUserWidget.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
AWeaponPickup::AWeaponPickup()
|
AWeaponPickup::AWeaponPickup()
|
||||||
{
|
{
|
||||||
|
WeaponPropertiesWidgetComponent = CreateDefaultSubobject<UWidgetComponent>(TEXT("Healthbar"));
|
||||||
|
WeaponPropertiesWidgetComponent->SetupAttachment(RootComponent);
|
||||||
|
WeaponPropertiesWidgetComponent->SetRelativeLocation(FVector(0,0,90));
|
||||||
|
WeaponPropertiesWidgetComponent->SetTwoSided(true);
|
||||||
|
WeaponPropertiesWidgetComponent->SetBackgroundColor(FLinearColor(1,1,1,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
|
@ -34,6 +42,18 @@ void AWeaponPickup::Tick(const float DeltaTime)
|
||||||
const float Sine = FMath::Abs(FMath::Sin(Time * MovementSpeed));
|
const float Sine = FMath::Abs(FMath::Sin(Time * MovementSpeed));
|
||||||
WeaponComponent->SetActorLocation(WeaponStartingLocation + ((MovementDirection * Sine) * MovementDistance));
|
WeaponComponent->SetActorLocation(WeaponStartingLocation + ((MovementDirection * Sine) * MovementDistance));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
if (PlayerCharacter && WeaponPropertiesWidgetComponent->GetWidget())
|
||||||
|
{
|
||||||
|
FVector ActorLocation = GetActorLocation();
|
||||||
|
|
||||||
|
UCameraComponent* PlayerCamera = PlayerCharacter->GetCameraComponent();
|
||||||
|
FVector PlayerLocation = PlayerCamera->GetComponentTransform().GetLocation();
|
||||||
|
|
||||||
|
FRotator rotation = UKismetMathLibrary::FindLookAtRotation(ActorLocation, PlayerLocation);
|
||||||
|
WeaponPropertiesWidgetComponent->SetWorldRotation(rotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
void AWeaponPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
|
||||||
|
@ -74,6 +94,23 @@ FWeaponProperties* AWeaponPickup::GetWeaponProperties()
|
||||||
void AWeaponPickup::SetWeaponProperties(const FWeaponProperties& FWeaponProperties) const
|
void AWeaponPickup::SetWeaponProperties(const FWeaponProperties& FWeaponProperties) const
|
||||||
{
|
{
|
||||||
WeaponComponent->SetWeaponProperties(FWeaponProperties);
|
WeaponComponent->SetWeaponProperties(FWeaponProperties);
|
||||||
|
|
||||||
|
UWeaponPickupUserWidget* userWidget = Cast<UWeaponPickupUserWidget>(WeaponPropertiesWidgetComponent->GetWidget());
|
||||||
|
|
||||||
|
userWidget->AmmoText->SetText(FText::AsNumber(FWeaponProperties.DefaultAmmo));
|
||||||
|
|
||||||
|
FString ProjectilesString = FString::FromInt(FWeaponProperties.ProjectilesPerShot);
|
||||||
|
ProjectilesString += "x";
|
||||||
|
userWidget->ProjectilesText->SetText(FText::FromString(ProjectilesString));
|
||||||
|
|
||||||
|
FString CooldownString = FString::SanitizeFloat(FWeaponProperties.WeaponCooldown);
|
||||||
|
CooldownString.LeftInline(3);
|
||||||
|
CooldownString += "s";
|
||||||
|
userWidget->CooldownText->SetText(FText::FromString(CooldownString));
|
||||||
|
|
||||||
|
FString SpreadString = FString::SanitizeFloat(FWeaponProperties.WeaponSpread);
|
||||||
|
SpreadString.LeftInline(4);
|
||||||
|
userWidget->SpreadText->SetText(FText::FromString(SpreadString));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AWeaponPickup::SpawnWeapon()
|
void AWeaponPickup::SpawnWeapon()
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "Pickup.h"
|
#include "Pickup.h"
|
||||||
#include "Weapon.h"
|
#include "Weapon.h"
|
||||||
|
#include "Components/WidgetComponent.h"
|
||||||
#include "WeaponPickup.generated.h"
|
#include "WeaponPickup.generated.h"
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
|
@ -30,6 +31,9 @@ public:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
float RotationSpeed = 50.0f;
|
float RotationSpeed = 50.0f;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
UWidgetComponent* WeaponPropertiesWidgetComponent;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
AWeapon* WeaponComponent;
|
AWeapon* WeaponComponent;
|
||||||
|
|
Loading…
Reference in New Issue