注:1.这个分类是按照源码里的注释分类的
2.本篇是通读并给出一些注释形式的,并不涉及结构性的分析
3.看之前要对UE的GAS系统的定义有初步了解
1 ApplyGameplayEffectSpecToTarget/Self
1.1 ApplyGameplayEffectSpecToTarget
应用一个已经创建的GameplayEffectSpec到目标,指向的是ASC
声明:
/** Applies a previously created gameplay effect spec to a target */
UFUNCTION(BlueprintCallable, Category = GameplayEffects, meta = (DisplayName = "ApplyGameplayEffectSpecToTarget", ScriptName = "ApplyGameplayEffectSpecToTarget"))
FActiveGameplayEffectHandle BP_ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpecHandle& SpecHandle, UAbilitySystemComponent* Target);
virtual FActiveGameplayEffectHandle ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpec& GameplayEffect, UAbilitySystemComponent *Target, FPredictionKey PredictionKey=FPredictionKey());
下面是实现:
1.SCOPE_CYCLE_COUNTER是系统中用来性能分析的,会记录执行时间
2.ShouldPredictTargetGameplayEffects() 是一个全局配置函数,用于判断是否需要对目标效果进行预测
如果全局配置中明确不需要预测目标效果,则将 PredictionKey重设为默认的构造(预测允许客户端提前执行某些操作,并在后续与服务器同步时修正结果,从而减少玩家感知到的延迟)
3.Target调用ApplyGameplayEffectSpecToSelf,并返回Handle
FActiveGameplayEffectHandle UAbilitySystemComponent::ApplyGameplayEffectSpecToTarget(const FGameplayEffectSpec &Spec, UAbilitySystemComponent *Target, FPredictionKey PredictionKey)
{
SCOPE_CYCLE_COUNTER(STAT_AbilitySystemComp_ApplyGameplayEffectSpecToTarget);
UAbilitySystemGlobals& AbilitySystemGlobals = UAbilitySystemGlobals::Get();
if (!AbilitySystemGlobals.ShouldPredictTargetGameplayEffects())
{
// If we don't want to predict target effects, clear prediction key
PredictionKey = FPredictionKey();
}
FActiveGameplayEffectHandle ReturnHandle;
if (Target)
{
ReturnHandle = Target->ApplyGameplayEffectSpecToSelf(Spec, PredictionKey);
}
return ReturnHandle;
}
1.2 ApplyGameplayEffectSpecToSelf
声明:
/** Applies a previously created gameplay effect spec to this component */
UFUNCTION(BlueprintCallable, Category = GameplayEffects, meta = (DisplayName = "ApplyGameplayEffectSpecToSelf", ScriptName = "ApplyGameplayEffectSpecToSelf"))
FActiveGameplayEffectHandle BP_ApplyGameplayEffectSpecToSelf(const FGameplayEffectSpecHandle& SpecHandle);
virtual FActiveGameplayEffectHandle ApplyGameplayEffectSpecToSelf(const FGameplayEffectSpec& GameplayEffect, FPredictionKey PredictionKey = FPredictionKey());
实现太长了,分段看:
(注释写在代码块里了)
#if WITH_SERVER_CODE
SCOPE_CYCLE_COUNTER(STAT_AbilitySystemComp_ApplyGameplayEffectSpecToSelf);
#endif
//还是同上,用于性能分析
// Scope lock the container after the addition has taken place to prevent the new effect from potentially getting mangled during the remainder
// of the add operation
FScopedActiveGameplayEffectLock ScopeLock

最低0.47元/天 解锁文章
2197

被折叠的 条评论
为什么被折叠?



