document.write("
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "DandelionGameplayAbility.h"
#include "InputActionValue.h"
#include "InputActionGameplayAbility.generated.h"
class ADandelionPlayerCharacter;
/**
* Native signature for the callback that will be raised in response to an InputAction event on an
* InputActionGameplayAbility.
* @param FInputActionValue The actual value that accompanied the original InputAction event.
*/
DECLARE_MULTICAST_DELEGATE_OneParam(FOnInputActionGameplayAbilityResponseSignature_Native, FInputActionValue);
/**
* BP signature for the callback that will be raised in response to an InputAction event on an
* InputActionGameplayAbility.
* @param Value The actual value that accompanied the original InputAction event.
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnInputActionGameplayAbilityResponseSignature, FInputActionValue, Value);
#pragma region EInputActionGameplayAbilityResponse
/**
* The specific response that an InputActionGameplayAbility should take in response to its InputAction being
* Pressed/Released.
*/
UENUM()
enum class EInputActionGameplayAbilityResponse
{
/**
* Default value. Literally do nothing and do not notify the GA.
*/
None,
/**
* Call EndAbility on the GA. Restart the ability if in response to OnInputPressed.
*/
EndAbility,
/**
* Call CancelAbility on the GA. Restart the ability if in response to OnInputPressed.
*/
CancelAbility,
/**
* Leaves handling of the response up to the child class/BP to implement. Also issues a callback via
* HandleInputReleased that can be overridden to actually implement the custom behavior for ending the GA. In the
* case of OnInputReleased, the GA must eventually call EndAbility or CancelAbility to avoid leaving a running GA.
*/
Custom
};
#pragma endregion
/**
* A specialized GameplayAbility that can respond to its InputAction being triggered if it has been mapped to via an
* instance of FInputActionGameplayAbilityMappingData with a Started TriggerType. Additionally, defines the desired
* response to the aforementioned InputAction being released/completed.
*/
UCLASS()
class DANDELION_API UInputActionGameplayAbility : public UDandelionGameplayAbility
{
GENERATED_BODY()
public:
/**
* Native event that is raised when the InputAction mapped to this IAGA has been triggered. Only raised if the
* defined in the FInputActionGameplayAbilityMappingData TriggerType was Started.
*/
FOnInputActionGameplayAbilityResponseSignature_Native OnTriggeredInputAction;
/**
* BP event that is raised when the IA mapped to this IAGA has been triggered. Only raised if the
* defined in the FInputActionGameplayAbilityMappingData TriggerType was Started.
*/
UPROPERTY(BlueprintReadWrite)
FOnInputActionGameplayAbilityResponseSignature OnTriggeredInputAction_BP;
/**
* Sets some default values regarding instancing and NetExecutionPolicy.
*/
UInputActionGameplayAbility();
protected:
/**
* The response that this IAGA should take when the corresponding InputAction defined in the
* FInputActionGameplayAbilityMappingData is pressed.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ability")
EInputActionGameplayAbilityResponse ResponseOnInputPressed = EInputActionGameplayAbilityResponse::None;
/**
* The response that this IAGA should take when the corresponding InputAction defined in the
* FInputActionGameplayAbilityMappingData is released.
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Ability")
EInputActionGameplayAbilityResponse ResponseOnInputReleased = EInputActionGameplayAbilityResponse::None;
/**
* Caches a reference to the ADandelionPlayerCharacter that has been granted this Ability.
* @param ActorInfo Information on the Actors that were involved in the granting of this Ability.
* @param Spec The FGameplayAbilitySpec of the granted ability.
*/
virtual void OnGiveAbility(const FGameplayAbilityActorInfo* ActorInfo, const FGameplayAbilitySpec& Spec) override;
/**
* When the ability is activated, check to see if there is a mapping for this GA in a
* FInputActionGameplayAbilityMappingData, and bind InvokeTriggeredInputAction to the callback for the IA being
* Triggered only if this IAGA was originally supposed to Activated off of the Started IA event.
* @param Handle Handle of the GameplayAbilitySpec that was activated.
* @param ActorInfo Actor Info for the activation of this ability.
* @param ActivationInfo Networking data related to the activation of this ability.
* @param TriggerEventData The FGameplayEventData that accompanied the activation of this ability.
*/
virtual void ActivateAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
const FGameplayEventData* TriggerEventData
) override;
/**
* When the IAGA ends, goes through the list of all bindings to the EnhancedInputComponent and removes them.
* @param Handle Handle of the GameplayAbilitySpec that was ended.
* @param ActorInfo Actor Info for the ending of this ability.
* @param ActivationInfo Networking data that was originally related to the activation of this ability.
* @param bReplicateEndAbility Whether the ending of this ability needs to be replicated to the client/server.
* @param bWasCancelled Whether this ability was cancelled or if it ended naturally.
*/
virtual void EndAbility(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo,
bool bReplicateEndAbility,
bool bWasCancelled
) override;
public:
/**
* Callback from the base GA class that is raised when the InputID associated with this GA is pressed. Determines
* what behavior to execute based on the ResponseOnInputPressed mode.
* @param Handle Handle of the GameplayAbilitySpec whose InputID was released.
* @param ActorInfo Actor Info for the release of the input of this ability.
* @param ActivationInfo Networking data that was originally related to the activation of this ability.
*/
virtual void InputPressed(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo
) override;
/**
* Callback from the base GA class that is raised when the InputID associated with this GA is released. Determines
* what behavior to execute based on the ResponseOnInputReleased mode.
* @param Handle Handle of the GameplayAbilitySpec whose InputID was released.
* @param ActorInfo Actor Info for the release of the input of this ability.
* @param ActivationInfo Networking data that was originally related to the activation of this ability.
*/
virtual void InputReleased(
const FGameplayAbilitySpecHandle Handle,
const FGameplayAbilityActorInfo* ActorInfo,
const FGameplayAbilityActivationInfo ActivationInfo
) override;
protected:
/**
* Cached reference to the DandelionPlayerCharacter that was originally the Avatar Actor for this GA.
*/
UPROPERTY(Transient)
TObjectPtr<ADandelionPlayerCharacter> DandelionPlayerCharacter;
/**
* Handler to be overridden by children classes/BP and called if the ResponseOnInputReleased is Custom.
* @param Handle Handle of the GameplayAbilitySpec whose InputID was released.
* @param ActorInfo Actor Info for the release of the input of this ability.
* @param ActivationInfo Networking data that was originally related to the activation of this ability.
*/
UFUNCTION(BlueprintNativeEvent)
void HandleInputPressed(
const FGameplayAbilitySpecHandle& Handle,
const FGameplayAbilityActorInfo& ActorInfo,
const FGameplayAbilityActivationInfo& ActivationInfo
);
virtual void HandleInputPressed_Implementation(
const FGameplayAbilitySpecHandle& Handle,
const FGameplayAbilityActorInfo& ActorInfo,
const FGameplayAbilityActivationInfo& ActivationInfo
);
/**
* Handler to be overridden by children classes/BP and called if the ResponseOnInputReleased is Custom.
* @param Handle Handle of the GameplayAbilitySpec whose InputID was released.
* @param ActorInfo Actor Info for the release of the input of this ability.
* @param ActivationInfo Networking data that was originally related to the activation of this ability.
*/
UFUNCTION(BlueprintNativeEvent)
void HandleInputReleased(
const FGameplayAbilitySpecHandle& Handle,
const FGameplayAbilityActorInfo& ActorInfo,
const FGameplayAbilityActivationInfo& ActivationInfo
);
virtual void HandleInputReleased_Implementation(
const FGameplayAbilitySpecHandle& Handle,
const FGameplayAbilityActorInfo& ActorInfo,
const FGameplayAbilityActivationInfo& ActivationInfo
);
private:
/**
* Cached reference to the EnhancedInputComponent that was on the PlayerController that possessed the
* DandelionPlayerCharacter.
*/
UPROPERTY(Transient)
TObjectPtr<UEnhancedInputComponent> EnhancedInputComponent;
/**
* The int values representing the EventHandles that were bound to the EnhancedInputComponent. Cached to prevent
* dangling bindings.
*/
TArray<uint32> TriggeredEventHandles;
/**
* Simple helper method that calls OnTriggeredInputAction. The native version gets called before the BP version.
* @param Value The FInputActionValue data that was associated with this invocation.
*/
void InvokeTriggeredInputAction(const FInputActionValue& Value);
};
InputActionGameplayAbility.h - Snippet hosted by \"Cacher\"
");