diff --git a/Content/Legumix/Player/BP_Player.uasset b/Content/Legumix/Player/BP_Player.uasset index 3803d2f..53b0c53 100644 --- a/Content/Legumix/Player/BP_Player.uasset +++ b/Content/Legumix/Player/BP_Player.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:555cf39cb18991be658039390eecbf091b172614e934e0090227ed060b6e641e -size 34703 +oid sha256:2db256cc9494b901f3f24e4b4d66f8d720b60fba52d250d031e334c0cfd5b5fc +size 35424 diff --git a/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset b/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset new file mode 100644 index 0000000..d90bc05 --- /dev/null +++ b/Content/Legumix/Weapon/BP_WeaponManagerComponent.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:792b2f2ab7e6dc725e9fbb7d949aa7d8ac23483a5ce1508c109ad5973dd1c474 +size 14988 diff --git a/Source/LegumeMix/Private/Player/LMPlayer.cpp b/Source/LegumeMix/Private/Player/LMPlayer.cpp index 2bcea73..ea031d4 100644 --- a/Source/LegumeMix/Private/Player/LMPlayer.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayer.cpp @@ -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(TEXT("Weapon Manager")); + + WeaponSkeletalMeshComponent = CreateDefaultSubobject(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); - } diff --git a/Source/LegumeMix/Private/Player/LMPlayerController.cpp b/Source/LegumeMix/Private/Player/LMPlayerController.cpp index 2ec8be3..2b74fd6 100644 --- a/Source/LegumeMix/Private/Player/LMPlayerController.cpp +++ b/Source/LegumeMix/Private/Player/LMPlayerController.cpp @@ -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(); EnhancedInputSubsystem->AddMappingContext(DefaultMappingContext, 0); - LegumixPlayer = Cast(GetPawn()); + LegumixPlayer = Cast(GetPawn()); } void ALMPlayerController::SetupInputComponent() diff --git a/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp new file mode 100644 index 0000000..6c88e97 --- /dev/null +++ b/Source/LegumeMix/Private/Weapon/LMWeaponManager.cpp @@ -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(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() + } +} + diff --git a/Source/LegumeMix/Public/Player/LMPlayer.h b/Source/LegumeMix/Public/Player/LMPlayer.h index effd765..71f46c6 100644 --- a/Source/LegumeMix/Public/Player/LMPlayer.h +++ b/Source/LegumeMix/Public/Player/LMPlayer.h @@ -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 WeaponManager; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta = (AllowPrivateAccess = true)) + TObjectPtr WeaponSkeletalMeshComponent; }; diff --git a/Source/LegumeMix/Public/Player/LMPlayerController.h b/Source/LegumeMix/Public/Player/LMPlayerController.h index 292022c..01dc307 100644 --- a/Source/LegumeMix/Public/Player/LMPlayerController.h +++ b/Source/LegumeMix/Public/Player/LMPlayerController.h @@ -7,6 +7,8 @@ #include "EnhancedInputSubsystems.h" #include "LMPlayerController.generated.h" +class ALMPlayer; + /** * */ @@ -35,7 +37,7 @@ private: TObjectPtr JumpAction; UPROPERTY(BlueprintReadOnly, meta = (AllowPrivateAccess = true)) - TObjectPtr LegumixPlayer; + TObjectPtr LegumixPlayer; virtual void SetupInputComponent() override; void Move(const FInputActionValue& InputValue); diff --git a/Source/LegumeMix/Public/Weapon/LMWeaponManager.h b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h new file mode 100644 index 0000000..977fa19 --- /dev/null +++ b/Source/LegumeMix/Public/Weapon/LMWeaponManager.h @@ -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 WeaponMeshComponent; + + /** The weapons the player starts with. */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix", meta=(AllowPrivateAccess=true)) + TArray> StartingWeapons; + + UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Legumix", meta=(AllowPrivateAccess=true)) + TArray> Weapons; + + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Legumix", meta=(AllowPrivateAccess=true)) + int CurrentWeaponIndex = 0; +};