DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnHealthChangedSignature, float, NewHealth);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMaxHealthChangedSignature,float,NewMaxHealth);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnManaChangedSignature,float,NewMana);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMaxManaChangedSignature,float,NewMaxMana);

UPROPERTY(BlueprintAssignable, Category = "GAS | Attributes")
FOnHealthChangedSignature OnHealthChanged;

UPROPERTY(BlueprintAssignable, Category = "GAS | Attributes")
FOnMaxHealthChangedSignature OnMaxHealthChanged;

UPROPERTY(BlueprintAssignable, Category = "GAS | Attributes")
FOnManaChangedSignature OnManaChanged;

UPROPERTY(BlueprintAssignable, Category = "GAS | Attributes")
FOnMaxManaChangedSignature OnMaxManaChanged;

广播:
const UAuraAttributeSet* AuraAttributeSet = CastChecked<UAuraAttributeSet>(AttributeSet);
OnHealthChanged.Broadcast(AuraAttributeSet->GetHealth());
OnMaxHealthChanged.Broadcast(AuraAttributeSet->GetMaxHealth());
OnManaChanged.Broadcast(AuraAttributeSet->GetMana());
OnMaxManaChanged.Broadcast(AuraAttributeSet->GetMaxMana());

绑定:
void UOverlayWidgetController::BindCallbacksToDependencies()
{
//Super::BindCallbacksToDependencies();
const UAuraAttributeSet* AuraAttributeSet = CastChecked<UAuraAttributeSet>(AttributeSet);

AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(
AuraAttributeSet->GetHealthAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnHealthChanged.Broadcast(Data.NewValue);
}
);

AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(
AuraAttributeSet->GetMaxHealthAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnMaxHealthChanged.Broadcast(Data.NewValue);
}
);

AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(
AuraAttributeSet->GetManaAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnManaChanged.Broadcast(Data.NewValue);
}
);

AbilitySystemComponent->GetGameplayAttributeValueChangeDelegate(
AuraAttributeSet->GetMaxManaAttribute()).AddLambda(
[this](const FOnAttributeChangeData& Data)
{
OnMaxManaChanged.Broadcast(Data.NewValue);
}
);

Cast<UAuraAbilitySystemComponent>(AbilitySystemComponent)->EffectAssetTags.AddLambda(
[this](const FGameplayTagContainer& AssetTags)
{
for (const FGameplayTag Tag : AssetTags)
{
FGameplayTag MessageTag = FGameplayTag::RequestGameplayTag(FName("Message"));
if (Tag.MatchesTag(MessageTag))
{
const FUIWidgetRow* Row = GatDataTableRowByTag<FUIWidgetRow>(MessageWidgetDataTable, Tag);
if (!Row) return;
MessageWidgetRowDelegate.Broadcast(*Row);
}
}
});
}
posted on 2025-08-26 17:57  偷懒的阿贤  阅读(6)  评论(0)    收藏  举报