Added player weapon display

This commit is contained in:
TjgL 2025-01-21 16:32:31 +01:00
parent 6da5f75089
commit 99707d1b73
9 changed files with 50 additions and 19 deletions

BIN
Content/Legumix/Player/BP_Player.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Legumix/Weapon/BP_WeaponManager.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -3,18 +3,20 @@
#include "Player/LMPlayer.h"
#include "Camera/CameraComponent.h"
#include "Weapon/LMWeaponManager.h"
ALMPlayer::ALMPlayer()
{
PrimaryActorTick.bCanEverTick = true;
WeaponManager = CreateDefaultSubobject<ULMWeaponManager>(TEXT("Weapon Manager"));
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(RootComponent);
Camera->bUsePawnControlRotation = true;
Camera->SetRelativeLocation(FVector(20, 0, 90));
WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon Mesh"));
WeaponSkeletalMeshComponent->SetupAttachment(GetMesh());
WeaponManager->SetWeaponMeshComponent(WeaponSkeletalMeshComponent);
WeaponSkeletalMeshComponent->SetupAttachment(Camera);
}
void ALMPlayer::BeginPlay()
@ -22,6 +24,19 @@ void ALMPlayer::BeginPlay()
Super::BeginPlay();
}
void ALMPlayer::SetWeaponManager(ULMWeaponManager* Manager)
{
UE_LOG(LogTemp, Warning, TEXT("Set weapon manager"))
if (!Manager)
{
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.f, FColor::Red, TEXT("No Weapon Manager was given to the player !"));
return;
}
WeaponManager = Manager;
WeaponManager->Initialize(WeaponSkeletalMeshComponent);
}
void ALMPlayer::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

View File

@ -22,10 +22,14 @@ void ULMWeaponManager::BeginPlay()
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
Weapons.Add(Instance);
// TODO
// Instance->Initialize();
Instance->Initialize();
}
}
}
void ULMWeaponManager::Initialize(USkeletalMeshComponent* Mesh)
{
SetWeaponMeshComponent(Mesh);
if (!Weapons.IsEmpty())
{
@ -69,6 +73,8 @@ void ULMWeaponManager::Reload()
void ULMWeaponManager::SetWeapon(int Index)
{
UE_LOG(LogTemp, Warning, TEXT("Test"))
if (Index < 0 || Index >= Weapons.Num())
{
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index");
@ -79,8 +85,9 @@ void ULMWeaponManager::SetWeapon(int Index)
if (WeaponMeshComponent)
{
// TODO
// WeaponMeshComponent->SetSkeletalMesh()
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Has Mesh");
WeaponMeshComponent->SetSkeletalMeshAsset(GetCurrentWeapon()->WeaponDataStructure.MeshWeapon);
}
}

View File

@ -6,6 +6,7 @@
#include "GameFramework/Character.h"
#include "LMPlayer.generated.h"
class UCameraComponent;
class ULMWeaponManager;
UCLASS()
@ -25,10 +26,16 @@ public:
UFUNCTION(BlueprintCallable)
ULMWeaponManager* GetWeaponManager() { return WeaponManager; }
UFUNCTION(BlueprintCallable)
void SetWeaponManager(ULMWeaponManager* Manager);
private:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<ULMWeaponManager> WeaponManager;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<USkeletalMeshComponent> WeaponSkeletalMeshComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
TObjectPtr<UCameraComponent> Camera;
};

View File

@ -14,7 +14,7 @@ struct FLMWeaponDataStructure : public FTableRowBase
int MaxClipAmmo; // Max ammo in clip
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TObjectPtr<UStaticMesh> MeshWeapon; //Mesh of the weapon display in the scene
TObjectPtr<USkeletalMesh> MeshWeapon; //Mesh of the weapon display in the scene
//UPROPERTY(EditAnywhere, BlueprintReadWrite)
//enum AmmoType; //Type of ammo, which ammo this weapon is using

View File

@ -38,6 +38,8 @@ public:
UFUNCTION(BlueprintCallable, Category="Legumix")
void Reload();
void Initialize(USkeletalMeshComponent* Mesh);
protected:
virtual void BeginPlay() override;