Add Weapon Switching Input Action and Callback
This commit is contained in:
parent
f002cfa870
commit
86b34b7226
Binary file not shown.
BIN
Content/Input/InputMappingContext.uasset (Stored with Git LFS)
BIN
Content/Input/InputMappingContext.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)
BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -107,6 +107,11 @@ void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputCom
|
||||||
Input->BindAction(SprintAction, ETriggerEvent::Started, this, &APlayerCharacter::SetSprintingCallback);
|
Input->BindAction(SprintAction, ETriggerEvent::Started, this, &APlayerCharacter::SetSprintingCallback);
|
||||||
Input->BindAction(SprintAction, ETriggerEvent::Completed, this, &APlayerCharacter::SetWalkingCallback);
|
Input->BindAction(SprintAction, ETriggerEvent::Completed, this, &APlayerCharacter::SetWalkingCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (WeaponSwitchingAction)
|
||||||
|
{
|
||||||
|
Input->BindAction(WeaponSwitchingAction, ETriggerEvent::Triggered, this, &APlayerCharacter::WeaponSwitchingCallback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,7 +234,7 @@ void APlayerCharacter::SetInventoryToDefault()
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::SelectInventorySlot(int slot)
|
void APlayerCharacter::SelectInventorySlot(int slot)
|
||||||
{
|
{
|
||||||
if (slot < WeaponInventory.Num())
|
if (slot < WeaponInventory.Num())
|
||||||
{
|
{
|
||||||
CurrentInventorySlot = slot;
|
CurrentInventorySlot = slot;
|
||||||
|
@ -237,20 +242,40 @@ void APlayerCharacter::SelectInventorySlot(int slot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::InventoryIncrementCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
|
||||||
{
|
{
|
||||||
SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num());
|
float value = Instance.GetValue().Get<float>();
|
||||||
}
|
|
||||||
|
|
||||||
void APlayerCharacter::InventoryDecrementCallback(const FInputActionInstance& Instance)
|
if (value > 0)
|
||||||
{
|
|
||||||
if (CurrentInventorySlot - 1 < 0)
|
|
||||||
{
|
{
|
||||||
SelectInventorySlot(WeaponInventory.Num() - 1);
|
InventoryIncrement();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num());
|
InventoryDecrement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::InventoryIncrement()
|
||||||
|
{
|
||||||
|
if (WeaponInventory.Num() > 0)
|
||||||
|
{
|
||||||
|
SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::InventoryDecrement()
|
||||||
|
{
|
||||||
|
if (WeaponInventory.Num() > 0)
|
||||||
|
{
|
||||||
|
if (CurrentInventorySlot - 1 < 0)
|
||||||
|
{
|
||||||
|
SelectInventorySlot(WeaponInventory.Num() - 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ public:
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TArray<AWeapon*> WeaponInventory;
|
TArray<AWeapon*> WeaponInventory;
|
||||||
|
|
||||||
// TODO: Add weapon switching actions
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
UInputAction* WeaponSwitchingAction;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -112,9 +113,11 @@ public:
|
||||||
|
|
||||||
void SelectInventorySlot(int slot);
|
void SelectInventorySlot(int slot);
|
||||||
|
|
||||||
void InventoryIncrementCallback(const FInputActionInstance& Instance);
|
void WeaponSwitchingCallback(const FInputActionInstance& Instance);
|
||||||
|
|
||||||
void InventoryDecrementCallback(const FInputActionInstance& Instance);
|
void InventoryIncrement();
|
||||||
|
|
||||||
|
void InventoryDecrement();
|
||||||
|
|
||||||
AWeapon* InitializeWeapon(TSubclassOf<class AWeapon> weapon);
|
AWeapon* InitializeWeapon(TSubclassOf<class AWeapon> weapon);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue