GAS学习
作者:互联网
GameplayAbilitySystem
GAS是Epic提供的一套技能解决方案,使用时需要在plugin启用Gameplay Abilities插件。
Ability & Input
- 处理输入的类需要实现IAbilitySystemInterface的接口,并且创建AbilitySystemComponent
//创建AbilitySystemComponent组件
AbilitySystemComponent = CreateDefaultSubobject(TEXT("AbilitySystemComponent"));
//重写该方法
UAbilitySystemComponent* AGasLearningCharacter::GetAbilitySystemComponent() const { return AbilitySystemComponent; }
- GAS依靠Key相同这一默认约定,将输入与技能ID做了绑定。
/** *key 要与项目input的设置一致,才能刚在gas里绑定 */
UENUM(BlueprintType) enum class EGASAbilityInputID : uint8 {
//0 None None UMETA(DisplayName = "None"),
//1 Jump Jump UMETA(DisplayName = "Jump"),
//2 Sprint Sprint UMETA(DisplalyName = "Sprint")
};
void Character::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
//绑定输入与释放的技能(通过枚举的key和Input的key一一对应)
AbilitySystemComponent->BindAbilityActivationToInputComponent(
PlayerInputComponent,
FGameplayAbilityInputBinds(
FString(),/**ConfirmTargetCommand*/
FString(),/**CancelTargetCommand*/
FString(TEXT("EGASAbilityInputID")),/**EnumName,即上面定义的枚举*/
static_cast(EGASAbilityInputID::None),/**ConfirmTargetInputID*/
static_cast(EGASAbilityInputID::None)/**CancelTargetInputID*/ ) );
}
/*关于Confirm和Cancel:
技能基本走的是这样的套路:
技能激活 --> 选择目标 --> 确认/取消 目标 --> 释放技能效果/中断技能
**/
- 技能ID与所释放技能的绑定
void Character::PossessedBy(AController* NewController)
{
Super::PossessedBy(NewController);
if(GetLocalRole() != ROLE_Authority || !IsValid(AbilitySystemComponent)) {
return /**处理多人游戏*/;
}
//给与技能
AbilitySystemComponent->GiveAbility(
FGameplayAbilitySpec(
UGameplayAbility_CharacterJump::StaticClass(),//使用GAS自带的跳跃技能实现
1,
static_cast(EGASAbilityInputID::Jump),
this)
);
//SprintAbility可以在蓝图实现
//UPROPERTY(BlueprintReadOnly, EditAnywhere)
//TSubclassOf SprintAbility;
if(SprintAbility) {
AbilitySystemComponent->GiveAbility(
FGameplayAbilitySpec(
SprintAbility,
1,
static_cast(EGASAbilityInputID::Sprint),
this )
);
}
/*关于蓝图实现技能:
创建GameplayAbility的子蓝图,实现EventActivateAbility
**/
}
AbilitySet & GameplayEffect
标签:AbilitySystemComponent,None,EGASAbilityInputID,GAS,学习,static,Jump,技能 来源: https://www.cnblogs.com/pixs-union/p/16471860.html