1.在CCAttributeSet.h中定义宏函数:
// * 要在游戏中使用它,您可以定义类似这样的内容,然后根据需要添加特定于游戏的功能:
#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
2.在属性后面使用:
UPROPERTY(BlueprintReadOnly, Category="Vital Attributes", ReplicatedUsing = OnRep_Health)
FGameplayAttributeData Health;
ATTRIBUTE_ACCESSORS(UCCAttributeSet, Health);
需要添加头文件:“#include "AbilitySystemComponent.h"”
3.构造函数:
UCCAttributeSet::UCCAttributeSet()
{
InitHealth(100.f);
InitMaxHealth(100.f);
InitMana(50.f);
InitMaxMana(50.f);
}
运行调试模式,按一下~,输入showdebug abilitysystem。看看:
完美!