Skip to content

Instantly share code, notes, and snippets.

@KaosSpectrum
Created August 6, 2018 13:46
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save KaosSpectrum/c602c6d57c315b7fa787420cfa89abfb to your computer and use it in GitHub Desktop.
Save KaosSpectrum/c602c6d57c315b7fa787420cfa89abfb to your computer and use it in GitHub Desktop.
// /*
// * (C) 2018 Kaos Interactive
// *
// * Part of the UltraWarz Project
// * No copying, using or selling of this code permitted unless explicity shared by Kaos Interactive.
// *
// * File created by KaosSpectrum (D.Moss)
// *
// * Last updated and cleaned: 06/08/2018 @ 14:44
// */
#include "UWTask_RepeatAction.h"
#include "TimerManager.h"
UUWTask_RepeatAction::UUWTask_RepeatAction(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{}
void UUWTask_RepeatAction::PerformAction() const
{
OnPerformAction.Broadcast();
}
UUWTask_RepeatAction* UUWTask_RepeatAction::RepeatAction(UGameplayAbility* OwningAbility, float DelayBetweenRepeats)
{
UUWTask_RepeatAction* MyObj = NewAbilityTask<UUWTask_RepeatAction>(OwningAbility);
MyObj->DelayBetweenRepeats = DelayBetweenRepeats;
return MyObj;
}
void UUWTask_RepeatAction::Activate()
{
PerformAction();
GetWorld()->GetTimerManager().SetTimer(TimerHandle_PerformAction, this, &UUWTask_RepeatAction::PerformAction, DelayBetweenRepeats, true);
}
void UUWTask_RepeatAction::OnDestroy(bool AbilityIsEnding)
{
GetWorld()->GetTimerManager().ClearTimer(TimerHandle_PerformAction);
Super::OnDestroy(AbilityIsEnding);
}
FString UUWTask_RepeatAction::GetDebugString() const
{
return FString::Printf(TEXT("RepeatAction"));
}
// /*
// * (C) 2018 Kaos Interactive
// *
// * Part of the UltraWarz Project
// * No copying, using or selling of this code permitted unless explicity shared by Kaos Interactive.
// *
// * File created by KaosSpectrum (D.Moss)
// *
// * Last updated and cleaned: 06/08/2018 @ 14:45
// */
#pragma once
#include "CoreMinimal.h"
#include "AbilityTask.h"
#include "UObject/ObjectMacros.h"
#include "Engine/EngineTypes.h"
#include "UWTask_RepeatAction.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FRepeatActionDelegate);
/**
*
*/
UCLASS()
class ULTRAWARZ_API UUWTask_RepeatAction : public UAbilityTask
{
GENERATED_BODY()
UUWTask_RepeatAction(const FObjectInitializer& ObjectInitializer);
UPROPERTY(BlueprintAssignable)
FRepeatActionDelegate OnPerformAction;
FString GetDebugString() const override;
void PerformAction() const;
/** Start a task that repeats an action or set of actions. */
UFUNCTION(BlueprintCallable, Category = "Ability|Tasks", meta = (DisplayName = "Repeat Action (Timer)", HidePin = "OwningAbility", DefaultToSelf = "OwningAbility", BlueprintInternalUseOnly = "TRUE"))
static UUWTask_RepeatAction* RepeatAction(UGameplayAbility* OwningAbility, float DelayBetweenRepeats);
void Activate() override;
protected:
float DelayBetweenRepeats;
/** Handle for efficient management of PerformAction timer */
FTimerHandle TimerHandle_PerformAction;
void OnDestroy(bool AbilityIsEnding) override;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment