AbilitySystemComponent

3.2k words

AbilitySystemComponent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

public class AbilitySystemComponent : MonoBehaviour, IAbilitySystemComponent{

[SerializeField]
private AbilitySystemComponentPreset preset;
public AbilitySystemComponentPreset Preset => preset;

public int Level { get; protected set; }

public GameplayEffectContainer GameplayEffectContainer { get; private set; }

public GameplayTagAggregator GameplayTagAggregator { get; private set; }

public AbilityContainer AbilityContainer { get; private set; }

public AttributeSetContainer AttributeSetContainer { get; private set; }

private bool _ready;

private void OnEnable()
{
...
GameplayAbilitySystem.GAS.Register(this);
GameplayTagAggregator?.OnEnable();
...
}

private void OnDisable()
{
...
GameplayAbilitySystem.GAS.Unregister(this);
}

#region 初始化
//根据现有的预制体,初始化ability、tag、attributeSet
public static void InitWithPreset(this AbilitySystemComponent asc, int level, AbilitySystemComponentPreset preset = null);
#endregion

#region GameplayEffect
//向目标执行对应的GE、中途会检测的tag和ge类型执行后续,最后调用 ApplyModFromInstantGameplayEffect
public GameplayEffectSpec ApplyGameplayEffectTo(GameplayEffect gameplayEffect, AbilitySystemComponent target);
public GameplayEffectSpec ApplyGameplayEffectTo(GameplayEffectSpec gameplayEffectSpec, AbilitySystemComponent target);

//根据GE对应的mmc去做数值的计算
public void ApplyModFromInstantGameplayEffect(GameplayEffectSpec spec);
#endregion

#region GameplayAbility
//Ability的添加
public AbilitySpec GrantAbility(AbstractAbility ability);
//Ability的移除
public void RemoveAbility(string abilityName);
public bool TryActivateAbility(string abilityName, params object[] args);
public void TryEndAbility(string abilityName);
public void TryCancelAbility(string abilityName);
private void DisableAllAbilities();


#endregion

}

IAbilitySystemComponent

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


public interface IAbilitySystemComponent
{
void SetPreset(AbilitySystemComponentPreset ascPreset);

void Init(GameplayTag[] baseTags, Type[] attrSetTypes, AbilityAsset[] baseAbilities,int level);

void SetLevel(int level);

bool HasTag(GameplayTag tag);

bool HasAllTags(GameplayTagSet tags);

bool HasAnyTags(GameplayTagSet tags);

void AddFixedTags(GameplayTagSet tags);
void AddFixedTag(GameplayTag gameplayTag);

void RemoveFixedTags(GameplayTagSet tags);
void RemoveFixedTag(GameplayTag gameplayTag);

GameplayEffectSpec ApplyGameplayEffectTo(GameplayEffect gameplayEffect,AbilitySystemComponent target);

GameplayEffectSpec ApplyGameplayEffectToSelf(GameplayEffect gameplayEffect);

void ApplyModFromInstantGameplayEffect(GameplayEffectSpec spec);

void RemoveGameplayEffect(GameplayEffectSpec spec);

void Tick();

Dictionary<string,float> DataSnapshot();

AbilitySpec GrantAbility(AbstractAbility ability);

void RemoveAbility(string abilityName);

float? GetAttributeCurrentValue(string setName,string attributeShortName);
float? GetAttributeBaseValue(string setName,string attributeShortName);

bool TryActivateAbility(string abilityName, params object[] args);
void TryEndAbility(string abilityName);

CooldownTimer CheckCooldownFromTags(GameplayTagSet tags);

T AttrSet<T>() where T : AttributeSet;

void ClearGameplayEffect();
}