初学GAS,仅用作自己查缺补漏,不想再做时又去找视频
参考教程:
英文原版(联机):Ambience Lee:
https://www.udemy.com/course/introduction-to-unreal-engine-4-ability-system/
中文翻译重置(单机):小明:
https://space.bilibili.com/149146076/channel/detail?cid=127939&ctype=0
一、碰到敌人时给自己推送伤害消息,Target为敌人
二、在GA中等待发送过来的Damage事件并对击中者设置效果,当动画播放完成或取消后停止StopAbility
三、设置击中效果GameplayEffect类
四、通过绑定变量变化反射来更新血量
4.1、自己创建血量UI并设置更新函数
4.2、c++中override PostGameplayEffectExecute函数进行属性改变检测,顺便进行生命值限制
AttributeSetBase.h
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnHealthChanged, float, CurHealth, float, MaxHealth);
UPROPERTY(BlueprintAssignable)
FOnHealthChanged OnHealthChanged;
void PostGameplayEffectExecute(const struct FGameplayEffectModCallbackData& Data) override;
AttributeSetBase.cpp
#include "AttributeSetBase.h"
#include "GameplayEffectExtension.h"
#include "GameplayEffect.h"
UAttributeSetBase::UAttributeSetBase()
:MaxHealth(100.f),Health(MaxHealth)
{
}
void UAttributeSetBase::PostGameplayEffectExecute(const struct FGameplayEffectModCallbackData& Data)
{
if (Data.EvaluatedData.Attribute.GetUProperty() == FindFieldChecked<FProperty>(UAttributeSetBase::StaticClass(), GET_MEMBER_NAME_CHECKED(UAttributeSetBase, Health)))
{
//生命值限制
Health.SetCurrentValue(FMath::Clamp(Health.GetCurrentValue(), 0.f, MaxHealth.GetCurrentValue()));
//生命值变化广播
OnHealthChanged.Broadcast( Health.GetCurrentValue(),MaxHealth.GetCurrentValue());
//打印生命值到Log
UE_LOG(LogTemp, Warning, TEXT("Health is %f"), Health.GetCurrentValue());
}
}
4.3、蓝图中自行绑定函数、加了死亡逻辑
这样一个具有简单逻辑的GAS项目就起来了