Gameplay Abilitie System(使角色获得能力)

11 篇文章 0 订阅

一、为Actor添加AbilitySystemComponent组件(这里以Character为例)
1、在VS里打开自定义Character脚本,引入头文件,使其继承IAbilitySystemInterface接口。

#include "AbilitySystemInterface.h"
class GASINTRO_API ATestCharacter : public ACharacter, public IAbilitySystemInterface

2、实现接口的GetAbilitySystemComponent方法,并声明其返回值类型的变量
TestCharacter.h:

public:
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "BaseCharacter")
	class UAbilitySystemComponent* AbilitySystemComponent;
public:	
	virtual UAbilitySystemComponent* GetAbilitySystemComponent() const;

TestCharacter.cpp:

#include "AbilitySystemComponent.h"
ATestCharacter::ATestCharacter()
{
	PrimaryActorTick.bCanEverTick = true;
	AbilitySystemComponent = CreateDefaultSubobject<UAbilitySystemComponent>("AbilitySystemComponent");
}
UAbilitySystemComponent* ATestCharacter::GetAbilitySystemComponent() const
{
	return AbilitySystemComponent;
}

二、通过AquireAbility让角色学会能力

TestCharacter.h:

public:	
	UFUNCTION(BlueprintCallable, Category = "BaseCharacter")
	void AquireAbility(TSubclassOf<UGameplayAbility> Ability);

注:FGameplayAbilitySpec其实是个结构体,可以查看其源码发现有很多初始化构造函数,包括能力等级等等

TestCharacter.cpp:

void ATestCharacter::AquireAbility(TSubclassOf<UGameplayAbility> Ability)
{
	if (AbilitySystemComponent && Ability)
	{
		AbilitySystemComponent->GiveAbility(FGameplayAbilitySpec(Ability)); //使用FGameplayAbilitySpec实例化Ability
		AbilitySystemComponent->InitAbilityActorInfo(this, this);//初始化能力信息,单机参数都是自己,如果跟网络相关,参数一个是Playerstadium,一个是Character类
	}
}

编译完成后创建C++的蓝图类,会发现多出来个Ability System Component组件
在这里插入图片描述

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I do not have access to the specific libraries of a particular programming language. However, I can provide a general explanation of what a system timer is and how it works. A system timer is a mechanism that allows a computer to keep track of time. It can be used to schedule tasks, measure the duration of operations, or trigger events at specific intervals. A system timer typically consists of a hardware component, such as a clock or a counter, and a software driver that interacts with the operating system. In Java, the Hutool library provides a SystemTimer class that allows you to schedule tasks to be executed at a specific time or after a certain delay. It uses the Java Timer class and provides some additional features such as the ability to schedule tasks with a fixed delay or a fixed rate, and to set a maximum number of executions. To use the Hutool SystemTimer, you first need to create an instance of the class and then use the schedule() method to schedule a task. The task can be a Runnable object or a lambda expression that defines the code to be executed. You can also specify the time or delay at which the task should be executed, as well as the number of times it should be executed. Here is an example code snippet that uses the Hutool SystemTimer to schedule a task to be executed after a 5-second delay: ``` import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.TimeInterval; import cn.hutool.core.thread.ThreadUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.ThreadUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.log.StaticLog; import cn.hutool.system.SystemUtil; public class SystemTimerDemo { public static void main(String[] args) { SystemTimer timer = new SystemTimer(); timer.schedule(() -> { System.out.println("Task executed after 5 seconds"); }, DateUtil.offsetSecond(DateUtil.date(), 5)); } } ``` In this example, we create a new instance of the SystemTimer class, and then use the schedule() method to schedule a task that prints a message to the console after a 5-second delay. We use the DateUtil.offsetSecond() method to calculate the time at which the task should be executed, and pass it as the second argument to the schedule() method. Overall, the Hutool SystemTimer provides a convenient and flexible way to schedule tasks in Java applications, and can be useful in a wide range of scenarios.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值