RPG21.创建敌人的AttributeSet,创建角色的GameplayEffect
1.打开AttributeSet
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "AbilitySystem/XMBAbilitySystemComponent.h"
#include "XMBAttributeSet.generated.h"#define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)/*** */
UCLASS()
class ARPG_GRIVITY_API UXMBAttributeSet : public UAttributeSet
{GENERATED_BODY()public:UXMBAttributeSet();UPROPERTY(BlueprintReadOnly, Category = "Health")FGameplayAttributeData CurrentHealth;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, CurrentHealth)UPROPERTY(BlueprintReadOnly, Category = "Health")FGameplayAttributeData MaxHealth;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, MaxHealth)UPROPERTY(BlueprintReadOnly, Category = "Rage")FGameplayAttributeData CurrentRage;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, CurrentRage)UPROPERTY(BlueprintReadOnly, Category = "Rage")FGameplayAttributeData MaxRage;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, MaxRage)UPROPERTY(BlueprintReadOnly, Category = "Damage")FGameplayAttributeData AttackPower;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, AttackPower)UPROPERTY(BlueprintReadOnly, Category = "Damage")FGameplayAttributeData DefensePower;ATTRIBUTE_ACCESSORS(UXMBAttributeSet, DefensePower)};
// Fill out your copyright notice in the Description page of Project Settings.#include "AbilitySystem/XMBAttributeSet.h"UXMBAttributeSet::UXMBAttributeSet()
{InitCurrentHealth(1.f);InitMaxHealth(1.f);InitCurrentRage(1.f);InitMaxRage(1.f);InitAttackPower(1.f);InitDefensePower(1.f);
}
2. 创建GE
创建linear的曲线表格,然后创建表格
然后设置GE
后面添加的三个属性也是一样的操作
3.再创建一个GE,用于设置玩家静态属性
对CurrentRage一样操作
4.接下来需要把创建好的GE设置在角色上,打开StartUpBase.h创建一个GE类型的变量
Protected:
UPROPERTY(EditDefaultsOnly, Category = "StartUpData")TArray<TSubclassOf<UGameplayEffect>> StartUpGameplayEffects;
逻辑写在GiveToAbilitySystemComponent()内
void UDataAsset_StartUpDataBase::GiveToAbilitySystemComponent(UXMBAbilitySystemComponent* InASCToGive, int32 ApplyLevel)
{check(InASCToGive);GrantAbilities(ActivateOnGivenAbilities, InASCToGive, ApplyLevel);GrantAbilities(ReactiveAbilities, InASCToGive, ApplyLevel);if (!StartUpGameplayEffects.IsEmpty()){for (const TSubclassOf<UGameplayEffect>& EffectClass : StartUpGameplayEffects){if (!EffectClass) continue;UGameplayEffect* EffectCDO = EffectClass->GetDefaultObject<UGameplayEffect>();InASCToGive->ApplyGameplayEffectToSelf(EffectCDO,ApplyLevel,InASCToGive->MakeEffectContext()//从目标 ASC 创建一个新的效果上下文,包含与效果应用相关的信息);}}
}
然后启动项目,打开DA_XMBStartUpAbilities
顺序不能乱,得先进行StartUp(能力创建)在进行Static(能力初始化)
5.接下来创建敌人的GE,先创加好表格
设置好Ge_StartUpAbility
然后设置GE_Static