Added weapon manager
This commit is contained in:
parent
59df20c639
commit
a107f650c8
BIN
Content/Legumix/Player/BP_Player.uasset
(Stored with Git LFS)
BIN
Content/Legumix/Player/BP_Player.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -3,32 +3,32 @@
|
||||
|
||||
#include "Player/LMPlayer.h"
|
||||
|
||||
// Sets default values
|
||||
#include "Weapon/LMWeaponManager.h"
|
||||
|
||||
ALMPlayer::ALMPlayer()
|
||||
{
|
||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
WeaponManager = CreateDefaultSubobject<ULMWeaponManager>(TEXT("Weapon Manager"));
|
||||
|
||||
WeaponSkeletalMeshComponent = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("Weapon Mesh"));
|
||||
WeaponSkeletalMeshComponent->SetupAttachment(GetMesh());
|
||||
|
||||
WeaponManager->SetWeaponMeshComponent(WeaponSkeletalMeshComponent);
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ALMPlayer::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ALMPlayer::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
}
|
||||
|
||||
// Called to bind functionality to input
|
||||
void ALMPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,14 @@
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "Player/LMPlayer.h"
|
||||
|
||||
void ALMPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
EnhancedInputSubsystem = GetLocalPlayer()->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>();
|
||||
EnhancedInputSubsystem->AddMappingContext(DefaultMappingContext, 0);
|
||||
LegumixPlayer = Cast<ACharacter>(GetPawn());
|
||||
LegumixPlayer = Cast<ALMPlayer>(GetPawn());
|
||||
}
|
||||
|
||||
void ALMPlayerController::SetupInputComponent()
|
||||
|
50
Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp
Normal file
50
Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "Weapon/LMWeaponManager.h"
|
||||
|
||||
#include "Weapon/LMWeapon.h"
|
||||
|
||||
|
||||
ULMWeaponManager::ULMWeaponManager()
|
||||
{
|
||||
PrimaryComponentTick.bCanEverTick = false;
|
||||
}
|
||||
|
||||
void ULMWeaponManager::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
for (auto Weapon : StartingWeapons)
|
||||
{
|
||||
if (Weapon)
|
||||
{
|
||||
ULMWeapon* Instance = NewObject<ULMWeapon>(this, Weapon);
|
||||
Weapons.Add(Instance);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Weapons.IsEmpty())
|
||||
{
|
||||
SetWeapon(CurrentWeaponIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ULMWeaponManager::SetWeapon(int Index)
|
||||
{
|
||||
if (Index < 0 || Index >= Weapons.Num())
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 5, FColor::Red, "Invalid Weapon Index");
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentWeaponIndex = Index;
|
||||
|
||||
if (WeaponMeshComponent)
|
||||
{
|
||||
// TODO
|
||||
// WeaponMeshComponent->SetSkeletalMesh()
|
||||
}
|
||||
}
|
||||
|
@ -6,24 +6,28 @@
|
||||
#include "GameFramework/Character.h"
|
||||
#include "LMPlayer.generated.h"
|
||||
|
||||
class ULMWeaponManager;
|
||||
|
||||
UCLASS()
|
||||
class LEGUMEMIX_API ALMPlayer : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
ALMPlayer();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// Called to bind functionality to input
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<ULMWeaponManager> WeaponManager;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<USkeletalMeshComponent> WeaponSkeletalMeshComponent;
|
||||
};
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "LMPlayerController.generated.h"
|
||||
|
||||
class ALMPlayer;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -35,7 +37,7 @@ private:
|
||||
TObjectPtr<UInputAction> JumpAction;
|
||||
|
||||
UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true))
|
||||
TObjectPtr<ACharacter> LegumixPlayer;
|
||||
TObjectPtr<ALMPlayer> LegumixPlayer;
|
||||
|
||||
virtual void SetupInputComponent() override;
|
||||
void Move(const FInputActionValue& InputValue);
|
||||
|
48
Source/LegumeMix/Public/Weapon/LMWeaponManager.h
Normal file
48
Source/LegumeMix/Public/Weapon/LMWeaponManager.h
Normal file
@ -0,0 +1,48 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Components/ActorComponent.h"
|
||||
#include "LMWeaponManager.generated.h"
|
||||
|
||||
|
||||
class ULMWeapon;
|
||||
|
||||
UCLASS(Blueprintable, BlueprintType, ClassGroup="Legumix", meta=(BlueprintSpawnableComponent))
|
||||
class LEGUMEMIX_API ULMWeaponManager : public UActorComponent
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ULMWeaponManager();
|
||||
void SetWeaponMeshComponent(USkeletalMeshComponent* Mesh) { WeaponMeshComponent = Mesh; }
|
||||
|
||||
public:
|
||||
/**
|
||||
* Get the Weapon currently equipped.
|
||||
* @return The Current Weapon.
|
||||
*/
|
||||
UFUNCTION(BlueprintCallable, Category="Legumix")
|
||||
ULMWeapon* GetCurrentWeapon() { return Weapons[CurrentWeaponIndex]; }
|
||||
|
||||
UFUNCTION(BlueprintCallable, Category="Legumix")
|
||||
void SetWeapon(int Index);
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix", meta = (AllowPrivateAccess = "true"))
|
||||
TObjectPtr<USkeletalMeshComponent> WeaponMeshComponent;
|
||||
|
||||
/** The weapons the player starts with. */
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix", meta=(AllowPrivateAccess=true))
|
||||
TArray<TSubclassOf<ULMWeapon>> StartingWeapons;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta=(AllowPrivateAccess=true))
|
||||
TArray<TObjectPtr<ULMWeapon>> Weapons;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix", meta=(AllowPrivateAccess=true))
|
||||
int CurrentWeaponIndex = 0;
|
||||
};
|
Reference in New Issue
Block a user