第一次提交
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "AsyncTasks/GGA_AsyncTask_AttributeChanged.h"
|
||||
|
||||
UGGA_AsyncTask_AttributeChanged* UGGA_AsyncTask_AttributeChanged::ListenForAttributeChange(UAbilitySystemComponent* AbilitySystemComponent, FGameplayAttribute Attribute)
|
||||
{
|
||||
if (!IsValid(AbilitySystemComponent) || !Attribute.IsValid())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UGGA_AsyncTask_AttributeChanged* WaitForAttributeChangedTask = NewObject<UGGA_AsyncTask_AttributeChanged>();
|
||||
WaitForAttributeChangedTask->SetAbilityActor(AbilitySystemComponent->GetAvatarActor());
|
||||
WaitForAttributeChangedTask->AttributeToListenFor = Attribute;
|
||||
|
||||
return WaitForAttributeChangedTask;
|
||||
}
|
||||
|
||||
UGGA_AsyncTask_AttributeChanged* UGGA_AsyncTask_AttributeChanged::ListenForAttributesChange(UAbilitySystemComponent* AbilitySystemComponent, TArray<FGameplayAttribute> Attributes)
|
||||
{
|
||||
if (!IsValid(AbilitySystemComponent) || Attributes.IsEmpty())
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UGGA_AsyncTask_AttributeChanged* WaitForAttributeChangedTask = NewObject<UGGA_AsyncTask_AttributeChanged>();
|
||||
WaitForAttributeChangedTask->SetAbilityActor(AbilitySystemComponent->GetAvatarActor());
|
||||
|
||||
WaitForAttributeChangedTask->AttributesToListenFor = Attributes;
|
||||
|
||||
return WaitForAttributeChangedTask;
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_AttributeChanged::EndTask()
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_AttributeChanged::Activate()
|
||||
{
|
||||
Super::Activate();
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
if (AttributeToListenFor.IsValid())
|
||||
{
|
||||
ASC->GetGameplayAttributeValueChangeDelegate(AttributeToListenFor).AddUObject(this, &ThisClass::AttributeChanged);
|
||||
}
|
||||
for (const FGameplayAttribute& Attribute : AttributesToListenFor)
|
||||
{
|
||||
if (Attribute.IsValid())
|
||||
{
|
||||
ASC->GetGameplayAttributeValueChangeDelegate(Attribute).AddUObject(this, &ThisClass::AttributeChanged);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_AttributeChanged::EndAction()
|
||||
{
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
if (AttributeToListenFor.IsValid())
|
||||
{
|
||||
ASC->GetGameplayAttributeValueChangeDelegate(AttributeToListenFor).RemoveAll(this);
|
||||
}
|
||||
|
||||
for (FGameplayAttribute Attribute : AttributesToListenFor)
|
||||
{
|
||||
if (AttributeToListenFor.IsValid())
|
||||
{
|
||||
ASC->GetGameplayAttributeValueChangeDelegate(Attribute).RemoveAll(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
Super::EndAction();
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_AttributeChanged::AttributeChanged(const FOnAttributeChangeData& Data)
|
||||
{
|
||||
OnAttributeChanged.Broadcast(Data.Attribute, Data.NewValue, Data.OldValue);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "AsyncTasks/GGA_AsyncTask_GameplayTagAddedRemoved.h"
|
||||
|
||||
UGGA_AsyncTask_GameplayTagAddedRemoved* UGGA_AsyncTask_GameplayTagAddedRemoved::ListenForGameplayTagAddedOrRemoved(UAbilitySystemComponent* AbilitySystemComponent, FGameplayTagContainer InTags)
|
||||
{
|
||||
UGGA_AsyncTask_GameplayTagAddedRemoved* TaskInstance = NewObject<UGGA_AsyncTask_GameplayTagAddedRemoved>();
|
||||
TaskInstance->SetAbilitySystemComponent(AbilitySystemComponent);
|
||||
TaskInstance->Tags = InTags;
|
||||
|
||||
if (!IsValid(AbilitySystemComponent) || InTags.Num() < 1)
|
||||
{
|
||||
TaskInstance->EndTask();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TArray<FGameplayTag> TagArray;
|
||||
InTags.GetGameplayTagArray(TagArray);
|
||||
|
||||
for (FGameplayTag Tag : TagArray)
|
||||
{
|
||||
AbilitySystemComponent->RegisterGameplayTagEvent(Tag, EGameplayTagEventType::NewOrRemoved).AddUObject(TaskInstance, &UGGA_AsyncTask_GameplayTagAddedRemoved::TagChanged);
|
||||
}
|
||||
|
||||
return TaskInstance;
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_GameplayTagAddedRemoved::EndTask()
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_GameplayTagAddedRemoved::EndAction()
|
||||
{
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
TArray<FGameplayTag> TagArray;
|
||||
Tags.GetGameplayTagArray(TagArray);
|
||||
|
||||
for (FGameplayTag Tag : TagArray)
|
||||
{
|
||||
ASC->RegisterGameplayTagEvent(Tag, EGameplayTagEventType::NewOrRemoved).RemoveAll(this);
|
||||
}
|
||||
}
|
||||
|
||||
Super::EndAction();
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_GameplayTagAddedRemoved::TagChanged(const FGameplayTag Tag, int32 NewCount)
|
||||
{
|
||||
if (NewCount > 0)
|
||||
{
|
||||
OnTagAdded.Broadcast(Tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
OnTagRemoved.Broadcast(Tag);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "AsyncTasks/GGA_AsyncTask_WaitGameplayAbilityActivated.h"
|
||||
|
||||
#include "AbilitySystemBlueprintLibrary.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
|
||||
UGGA_AsyncTask_WaitGameplayAbilityActivated* UGGA_AsyncTask_WaitGameplayAbilityActivated::WaitGameplayAbilityActivated(AActor* TargetActor)
|
||||
{
|
||||
UGGA_AsyncTask_WaitGameplayAbilityActivated* MyObj = NewObject<UGGA_AsyncTask_WaitGameplayAbilityActivated>();
|
||||
MyObj->SetAbilityActor(TargetActor);
|
||||
MyObj->SetAbilitySystemComponent(UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetActor));
|
||||
return MyObj;
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityActivated::HandleAbilityActivated(UGameplayAbility* Ability)
|
||||
{
|
||||
if (ShouldBroadcastDelegates())
|
||||
{
|
||||
OnAbilityActivated.Broadcast(Ability);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
bool UGGA_AsyncTask_WaitGameplayAbilityActivated::ShouldBroadcastDelegates() const
|
||||
{
|
||||
return Super::ShouldBroadcastDelegates();
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityActivated::Activate()
|
||||
{
|
||||
Super::Activate();
|
||||
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
DelegateHandle = ASC->AbilityActivatedCallbacks.AddUObject(this, &UGGA_AsyncTask_WaitGameplayAbilityActivated::HandleAbilityActivated);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityActivated::EndAction()
|
||||
{
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
if (DelegateHandle.IsValid())
|
||||
{
|
||||
ASC->AbilityActivatedCallbacks.Remove(DelegateHandle);
|
||||
}
|
||||
}
|
||||
Super::EndAction();
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
|
||||
#include "AsyncTasks/GGA_AsyncTask_WaitGameplayAbilityEnded.h"
|
||||
#include "Runtime/Launch/Resources/Version.h"
|
||||
#include "AbilitySystemBlueprintLibrary.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
|
||||
UGGA_AsyncTask_WaitGameplayAbilityEnded* UGGA_AsyncTask_WaitGameplayAbilityEnded::WaitGameplayAbilityEnded(AActor* TargetActor,
|
||||
FGameplayTagQuery AbilityQuery)
|
||||
{
|
||||
UGGA_AsyncTask_WaitGameplayAbilityEnded* MyObj = NewObject<UGGA_AsyncTask_WaitGameplayAbilityEnded>();
|
||||
MyObj->SetAbilityActor(TargetActor);
|
||||
MyObj->SetAbilitySystemComponent(UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetActor));
|
||||
MyObj->AbilityQuery = AbilityQuery;
|
||||
return MyObj;
|
||||
}
|
||||
|
||||
UGGA_AsyncTask_WaitGameplayAbilityEnded* UGGA_AsyncTask_WaitGameplayAbilityEnded::WaitAbilitySpecHandleEnded(AActor* TargetActor, FGameplayAbilitySpecHandle AbilitySpecHandle)
|
||||
{
|
||||
UGGA_AsyncTask_WaitGameplayAbilityEnded* MyObj = NewObject<UGGA_AsyncTask_WaitGameplayAbilityEnded>();
|
||||
MyObj->SetAbilityActor(TargetActor);
|
||||
MyObj->SetAbilitySystemComponent(UAbilitySystemBlueprintLibrary::GetAbilitySystemComponent(TargetActor));
|
||||
MyObj->AbilitySpecHandle = AbilitySpecHandle;
|
||||
return MyObj;
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityEnded::HandleAbilityEnded(const FAbilityEndedData& Data)
|
||||
{
|
||||
if (ShouldBroadcastDelegates())
|
||||
{
|
||||
if (!AbilityQuery.IsEmpty())
|
||||
{
|
||||
#if ENGINE_MINOR_VERSION > 4
|
||||
if (AbilityQuery.Matches(Data.AbilityThatEnded->GetAssetTags()))
|
||||
#else
|
||||
if (AbilityQuery.Matches(Data.AbilityThatEnded->AbilityTags))
|
||||
#endif
|
||||
{
|
||||
OnAbilityEnded.Broadcast(Data);
|
||||
}
|
||||
}
|
||||
|
||||
if (AbilitySpecHandle.IsValid() && AbilitySpecHandle == Data.AbilitySpecHandle)
|
||||
{
|
||||
OnAbilityEnded.Broadcast(Data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityEnded::Activate()
|
||||
{
|
||||
Super::Activate();
|
||||
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
DelegateHandle = ASC->OnAbilityEnded.AddUObject(this, &UGGA_AsyncTask_WaitGameplayAbilityEnded::HandleAbilityEnded);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndAction();
|
||||
}
|
||||
}
|
||||
|
||||
void UGGA_AsyncTask_WaitGameplayAbilityEnded::EndAction()
|
||||
{
|
||||
if (UAbilitySystemComponent* ASC = GetAbilitySystemComponent())
|
||||
{
|
||||
if (DelegateHandle.IsValid())
|
||||
{
|
||||
ASC->AbilityEndedCallbacks.Remove(DelegateHandle);
|
||||
}
|
||||
}
|
||||
Super::EndAction();
|
||||
}
|
||||
Reference in New Issue
Block a user