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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,13 +242,32 @@ 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>();
|
||||||
|
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
InventoryIncrement();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InventoryDecrement();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void APlayerCharacter::InventoryDecrementCallback(const FInputActionInstance& Instance)
|
void APlayerCharacter::InventoryIncrement()
|
||||||
{
|
{
|
||||||
|
if (WeaponInventory.Num() > 0)
|
||||||
|
{
|
||||||
|
SelectInventorySlot((CurrentInventorySlot + 1) % WeaponInventory.Num());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void APlayerCharacter::InventoryDecrement()
|
||||||
|
{
|
||||||
|
if (WeaponInventory.Num() > 0)
|
||||||
|
{
|
||||||
if (CurrentInventorySlot - 1 < 0)
|
if (CurrentInventorySlot - 1 < 0)
|
||||||
{
|
{
|
||||||
SelectInventorySlot(WeaponInventory.Num() - 1);
|
SelectInventorySlot(WeaponInventory.Num() - 1);
|
||||||
|
@ -252,6 +276,7 @@ void APlayerCharacter::InventoryDecrementCallback(const FInputActionInstance& In
|
||||||
{
|
{
|
||||||
SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num());
|
SelectInventorySlot((CurrentInventorySlot - 1) % WeaponInventory.Num());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon)
|
AWeapon* APlayerCharacter::InitializeWeapon(TSubclassOf<class AWeapon> weapon)
|
||||||
|
|
|
@ -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