第2章---初次接触GAS系统

文件结构:

更新文件将高亮显示

  • Source
    • Private
      • AbilitySystemComponent
        • RPGAbilitySystemComponent.cpp
        • RPGAttributeSet.cpp
      • Character
        • PGGameCharacterBase.cpp
        • RPGGameEnemy.cpp
        • RPGGamePlayerCharacter.cpp
      • Game
        • RPGGameModeBase.cpp
      • Interaction
        • EnemyInterface.cpp
      • Player
        • RPGPlayerController.cpp
        • RPGPlayerState.cpp
    • Public
      • AbilitySystemComponent
        • RPGAbilitySystemComponent.h
        • RPGAttributeSet.h
      • Character
        • RPGGameCharacterBase.h
        • RPGGameEnemy.h
        • RPGGamePlayerCharacter.h
      • Game
        • RPGGameModeBase.h
      • Interaction
        • EnemyInterface.h
      • Player
        • RPGPlayerController.h
        • RPGPlayerState.h

文件表述:

RPGAbilitySystemComponent

定义一个自定义的ASC类

.h文件
// Copyright KimiLiu#pragma once#include "CoreMinimal.h"
#include "AbilitySystemComponent.h"
#include "RPGAbilitySystemComponent.generated.h"/*** Ability System Component 拥有两个Owner: Owner Actor 以及Avatar Actor,这两个Actor有可能相同,有可能不相同*	Owner Actor 指的是实例化组件的Actor*	Avatar Actor 指的是ASC实际上服务的Actor,例如*		- RPGGameEnemy 内的ASC的 Owner Actor 和 Avatar Actor 都是 RPGGameEnemy 这个 Actor 类自身。因为ASC由 RPGGameEnemy 实例*			化,同时服务于 RPGGameEnemy*		- RPGGamePlayerCharacter 内的ASC的 Owner Actor 是 RPGPlayerState,而 Avatar Actor 是RPGGamePlayerCharacter。因为*			ASC由RPGPlayerState实例化,但是ASC服务于PRGGamePlayerCharacter*/
UCLASS()
class AURA_API URPGAbilitySystemComponent : public UAbilitySystemComponent
{GENERATED_BODY()};
.cpp文件
// Copyright KimiLiu#include "AbilitySytstem/RPGAbilitySystemComponent.h"

RPGAttributeSet

新建一个自定义的属性集

.h文件
// Copyright KimiLiu#pragma once#include "CoreMinimal.h"
#include "AttributeSet.h"
#include "RPGAttributeSet.generated.h"/*** */
UCLASS()
class AURA_API URPGAttributeSet : public UAttributeSet
{GENERATED_BODY()};
.cpp文件
// Copyright KimiLiu#include "AbilitySytstem/RPGAttributeSet.h"

PGGameCharacterBase

.h文件

声明ASC组件以及AS组件,实现IAbilitySystemInterface接口内的GetAbilitySystemComponent()函数,新增GetAttributeSet()函数

// Copyright KimiLiu#pragma once#include "CoreMinimal.h"
#include "AbilitySytstem/RPGAbilitySystemComponent.h"
#include "AbilitySystemInterface.h"
#include "GameFramework/Character.h"
#include "RPGGameCharacterBase.generated.h"class UAbilitySystemComponent;
class UAttributeSet;UCLASS(Abstract)
class AURA_API ARPGGameCharacterBase : public ACharacter, public IAbilitySystemInterface
{GENERATED_BODY()public:ARPGGameCharacterBase();virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;UAttributeSet* GetAttributeSet() const {return AttributeSet;}protected:virtual void BeginPlay() override;//后续开发尽量使用TObjectPtr<>来声明变量,可以给开发带来许多便利(蓝图内)UPROPERTY(EditAnywhere, Category="Combat")TObjectPtr<USkeletalMeshComponent> Weapon;//在此处声明GAS组件以及AttributeSet,但是只在Enemy类中实例化而不在PlayerCharacter中实例化//PlayerCharacter的GAS组件以及AttributeSet会在PlayerState中实例化(联网以及单机都可用)UPROPERTY()TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;UPROPERTY()TObjectPtr<UAttributeSet> AttributeSet;
};
.cpp文件

无改变

RPGGameEnemy

.h文件

无改变

.cpp文件

实例化父类声明的AbilitySystemComponent以及AttributeSet,在BeginPlay()函数中设置AbilitySystemComponent的两个Owner为该类本身

// Copyright KimiLiu#include "..\..\Public\Character\RPGGameEnemy.h"#include "AbilitySytstem/RPGAttributeSet.h"
#include "Aura/Aura.h"ARPGGameEnemy::ARPGGameEnemy()
{GetMesh()->SetCollisionResponseToChannel(ECC_Visibility, ECR_Block);//实例化GAS组件,同时开启复制(复制相关功能只与网络有关)AbilitySystemComponent = CreateDefaultSubobject<URPGAbilitySystemComponent>("AbilitySystemComponent");AbilitySystemComponent->SetIsReplicated(true);AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Minimal);AttributeSet = CreateDefaultSubobject<URPGAttributeSet>("AttributeSet");}void ARPGGameEnemy::HighlightActor()
{GetMesh()->SetRenderCustomDepth(true);GetMesh()->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED);Weapon->SetRenderCustomDepth(true);Weapon->SetCustomDepthStencilValue(CUSTOM_DEPTH_RED);
}void ARPGGameEnemy::UnHighlightActor()
{GetMesh()->SetRenderCustomDepth(false);Weapon->SetRenderCustomDepth(false);
}void ARPGGameEnemy::BeginPlay()
{Super::BeginPlay();AbilitySystemComponent->InitAbilityActorInfo(this, this);
}

RPGGamePlayerCharacter

.h文件

新增两个重写函数:PossessedBy()以及OnRep_PlayerState(),新增一个函数InitAbilityActorInfo()

// Copyright KimiLiu#pragma once#include "CoreMinimal.h"
#include "RPGGameCharacterBase.h"
#include "RPGGamePlayerCharacter.generated.h"/*** */
UCLASS()
class AURA_API ARPGGamePlayerCharacter : public ARPGGameCharacterBase
{GENERATED_BODY()public:ARPGGamePlayerCharacter();virtual void PossessedBy(AController* NewController) override;virtual void OnRep_PlayerState() override;private:void InitAbilityActorInfo();
};
.cpp文件
// Copyright KimiLiu#include "Character\RPGGamePlayerCharacter.h"#include "GameFramework/CharacterMovementComponent.h"
#include "Player/RPGPlayerState.h"ARPGGamePlayerCharacter::ARPGGamePlayerCharacter()
{//角色始终面向移动方向GetCharacterMovement()->bOrientRotationToMovement = true;GetCharacterMovement()->RotationRate = FRotator(0.f, 400.f, 0.f);GetCharacterMovement()->bConstrainToPlane = true;//将运动约束在平面上//角色不会面向控制器的方向bUseControllerRotationPitch = false;bUseControllerRotationRoll = false;bUseControllerRotationYaw = false;}void ARPGGamePlayerCharacter::PossessedBy(AController* NewController)
{Super::PossessedBy(NewController);// Init ability actor info for the SeverInitAbilityActorInfo();
}void ARPGGamePlayerCharacter::OnRep_PlayerState()
{Super::OnRep_PlayerState();// Init ability actor info for the ClientInitAbilityActorInfo();
}void ARPGGamePlayerCharacter::InitAbilityActorInfo()
{ARPGPlayerState* RPGPlayerState = GetPlayerState<ARPGPlayerState>();check(RPGPlayerState);RPGPlayerState->GetAbilitySystemComponent()->InitAbilityActorInfo(RPGPlayerState, this);//不在构造器内初始化,而是在被分配了Controller后将Controller内的AbilitySystemComponent和AttributeSet赋值给当前对象AbilitySystemComponent = RPGPlayerState->GetAbilitySystemComponent();AttributeSet = RPGPlayerState->GetAttributeSet();
}

RPGPlayerState

.h文件

声明ASC组件以及AS组件,实现IAbilitySystemInterface接口内的GetAbilitySystemComponent()函数,新增GetAttributeSet()函数

// Copyright KimiLiu#pragma once#include "CoreMinimal.h"
#include "AbilitySystemInterface.h"
#include "GameFramework/PlayerState.h"
#include "RPGPlayerState.generated.h"class UAbilitySystemComponent;
class UAttributeSet;/*** */
UCLASS()
class AURA_API ARPGPlayerState : public APlayerState, public IAbilitySystemInterface
{GENERATED_BODY()public:ARPGPlayerState();virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;UAttributeSet* GetAttributeSet() const {return AttributeSet;}protected:UPROPERTY()TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;UPROPERTY()TObjectPtr<UAttributeSet> AttributeSet;
};
.cpp文件

注意看注释,注释写了不同的复制模式以及需要注意的点,在写单机游戏的时候将多人游戏一起考虑进去准没错

// Copyright KimiLiu#include "Player/RPGPlayerState.h"#include "AbilitySytstem/RPGAbilitySystemComponent.h"
#include "AbilitySytstem/RPGAttributeSet.h"ARPGPlayerState::ARPGPlayerState()
{//服务器更新客户端频率,单机游戏不需要写,看需求,把多人的一起写了NetUpdateFrequency = 100.f;//实例化GAS组件,同时开启复制(复制相关功能只与网络有关)AbilitySystemComponent = CreateDefaultSubobject<URPGAbilitySystemComponent>("AbilitySystemComponent");AbilitySystemComponent->SetIsReplicated(true);/*** Replication Mode :*	Full:*		-UseCase: Single player(单人游戏)*		-Description: Gameplay Effects are replicated to all clients(GE会被所有客户端复制)*	Mixed:*		-UseCase: Multiplayer, Player-Controlled(多人游戏,玩家操作)*		-Description: Gameplay Effects are replicated to the owning client only. Gameplay Cues and Gameplay Tags*			replicated to all clients(GE会被拥有它的客户端复制, GC和GT会被所有客户端复制)*		-OwnerActor's Owner must be the Controller. For Pawns, this is set automatically in PossessedBy();(当*			Controller 被分配的时候,PossessedBy()这个函数会被调用,其他情况下PossessedBy()不会被调用,因此当我们项目中的某个类的*			ASC的 Owner 的 Owner 不是Controller的时候,我们需要在这个类中主动调用SetOwner()来将这个类的Owner设置为Controller)*		-By default, the PlayerState's Owner is automatically set to the Controller;*		-Therefore, if your OwnerActor is not the PlayerState, and you use Mixed Replication Mode, you must call*			SetOwner() on the OwnerActor to set its owner to the Controller;*	Minimal:*		-UseCase: Multiplayerm AI_Controlled(多人游戏,AI操作)*		-Description: Gameplay Effects are not replicated. Gameplay Cues and Gameplay Tags replicated to all clients*			(GE不会被复制,GC和GT会被所有客户端复制)*/AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);AttributeSet = CreateDefaultSubobject<URPGAttributeSet>("AttributeSet");
}UAbilitySystemComponent* ARPGPlayerState::GetAbilitySystemComponent() const
{return AbilitySystemComponent;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/728220.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java 8 Supplier函数式接口介绍及代码样例

介绍 供应商接口&#xff08;Supplier Interface&#xff09;是 Java 8 引入的 java.util.function 包的一部分&#xff0c;用于在 Java 中实现函数式编程。它表示一个函数&#xff0c;该函数不接收任何参数&#xff0c;但会产生一个类型为 T 的值。 T&#xff1a;表示结果的类…

Vue3+ts(day01:Vue3简介、初始化Vue3工程)

学习源码可以看我的个人前端学习笔记 (github.com):qdxzw/frontlearningNotes 觉得有帮助的同学&#xff0c;可以点心心支持一下哈&#xff08;笔记是根据b站上学习的尚硅谷的前端视频【张天禹老师】&#xff0c;记录一下学习笔记&#xff0c;用于自己复盘&#xff0c;有需要学…

JavaBean、POJO、Entity、ValueObject区别

JavaBean、POJO、Entity 和 ValueObject&#xff08;也称为VO&#xff09;是软件开发中常用的一些术语&#xff0c;它们在特定上下文中可能有所不同&#xff0c;但通常用于描述数据传输对象或模型的不同概念。以下是它们的一般区别&#xff1a; JavaBean JavaBean是一种符合特定…

基于arduino板的写字机设计

目 录 摘 要 Abstract 引 言 1 总体方案设计 1.1 系统方案设计 1.2 系统工作原理 2 硬件电路的设计 2.1 主控模块设计 2.2 驱动模块设计 2.3 时钟模块设计 2.4 总电路设计 3 软件设计 3.1 Arduino开发环境 3.2 主程序设计 3.3 抬笔落笔的子程序设计 3.4 摆臂子…

【华为OD机试】转盘寿司【C卷|100分】

【华为OD机试】-真题 !!点这里!! 【华为OD机试】真题考点分类 !!点这里 !! 题目描述 寿司店周年庆,正在举办优惠活动回馈新老客户。 寿司转盘上总共有 n 盘寿司,prices[i] 是第 i 盘寿司的价格, 如果客户选择了第 i 盘寿司,寿司店免费赠送客户距离第 i 盘寿司最近的下一…

LeetCode 2161.根据给定数字划分数组

给你一个下标从 0 开始的整数数组 nums 和一个整数 pivot 。请你将 nums 重新排列&#xff0c;使得以下条件均成立&#xff1a; 所有小于 pivot 的元素都出现在所有大于 pivot 的元素 之前 。 所有等于 pivot 的元素都出现在小于和大于 pivot 的元素 中间 。 小于 pivot 的元素…

Seata 2.x 系列【2】数据库事务

有道无术&#xff0c;术尚可求&#xff0c;有术无道&#xff0c;止于术。 本系列Spring Boot 版本 3.1.0 本系列Seata 版本 2.0.0 源码地址&#xff1a;https://gitee.com/pearl-organization/study-seata-demo 文章目录 1. 概述2. ACID 模型2.1 原子性2.2 一致性2.3 隔离性2…

题记(48)--L1-016 查验身份证

目录 一、题目内容 二、输入描述 三、输出描述 四、输入输出示例 五、完整C语言代码 一、题目内容 一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下&#xff1a; 首先对前17位数字加权求和&#xff0c;权重分配为&#xff1a;{…

Postman报错提示 Could not get any response怎么解决

在通过postman请求做接口测试的过程中&#xff0c;有时候会遇到一些报错&#xff0c;当遇到这些报错我们不要着急&#xff0c;看着具体哪里报错&#xff0c;然后进行解决 postman报错 经常使用postman的小伙伴们都应该遇到过一些报错&#xff0c;遇到报错的时候我们不要着急&…

这可是全网网工华为认证学习笔记最完整,最详细的版本,没有之一

文章篇幅较长&#xff0c;耐心看完你一定有所收获。 华为认证是什么&#xff1f; 其实就是由华为公司所提出的评价网络工程师专业能力的一个认证&#xff0c;它分为三个级别&#xff0c;分别是这个华为认证的工程师&#xff08;HCIA&#xff09;&#xff0c;华为认证的高级工程…

探索程序员职业赛道:中国行业发展趋势与市场需求分析

目录 写在开头1.中国行业发展趋势与市场需求分析1.1. 前端开发1.2. 后端开发1.3. 数据科学与人工智能1.4. 区块链技术1.5 软件工程与项目管理1.6 嵌入式开发与物联网 2.如何选择适合自己的职业赛道写在最后 写在开头 作为程序员&#xff0c;选择适合自己的职业赛道是至关重要的…

CTP-API开发系列之三:柜台系统简介

CTP-API开发系列之三&#xff1a;柜台系统简介 CTP-API开发系列之三&#xff1a;柜台系统简介中国金融市场结构---交易所柜台系统通用柜台系统极速柜台系统主席与次席 CTP柜台系统CTP组件名称对照表CTP柜台系统程序包CTP柜台系统架构图 CTP-API开发系列之三&#xff1a;柜台系统…

重新排序。

问题描述 给定一个数组A和一些查询 L,R求数组中第L至第 R个元素之和。 小蓝觉得这个问题很无聊,于是他想重新排列一下数组使得最终每个查 询结果的和尽可能地大。小蓝想知道相比原数组,所有查询结果的总和最多可 以增加多少? 输入格式 输入第一行包含一个整数n。 第二行包含n个…

钉钉群内自定义机器人发送消息功能实现

文章目录 钉钉群内自定义机器人发送消息功能实现1、设置webhook自定义机器人2、查看官方文档&#xff0c;使用open api3、编写业务代码4、发送成功结果如下 钉钉群内自定义机器人发送消息功能实现 1、设置webhook自定义机器人 设置关键词 添加完成后&#xff0c;获得改机器人的…

直流电磁铁计算公式

直流电磁铁计算公式 1. 磁势2. 磁场强度3. 磁感应强度4. 电磁吸力5. 线圈发热 1. 磁势 产生磁场的磁势计算公式&#xff1a; F N ⋅ I FN \cdot I FN⋅I N&#xff1a;是线圈匝数&#xff0c;I&#xff1a;是线圈中的电流注&#xff1a;线圈过热&#xff0c;可以减小电流&am…

力扣--从前序与中序遍历序列构造二叉树

题目&#xff1a; 思想&#xff1a; 首先先序遍历能确定根节点的值&#xff0c;此时查看该值在中序遍历中的位置&#xff08;如果索引为i&#xff09;&#xff0c;那么i左侧为左子树&#xff0c;i 右侧为右子树。从中序数组中即可看出左子树结点个数为 i&#xff0c;右子树节点…

浅析扩散模型与图像生成【应用篇】(八)——BBDM

8. BBDM: Image-to-Image Translation with Brownian Bridge Diffusion Models 本文提出一种基于布朗桥&#xff08;Brownian Bridge&#xff09;的扩散模型用于图像到图像的转换。图像到图像转换的目标是将源域 A A A中的图像 I A I_A IA​&#xff0c;映射到目标域 B B B中得…

大唐杯学习笔记:Day7

1.1 随机接入 随机接入概述 UE完成下行同步后,根据不同的触发场景,进行随机接入过程,完成UE和基站之间的上行同步。包括竞争随机接入和非竞争随机接入。 随机接入信道结构 CPSequenceGT T C P T_{CP} TCP​ T μ T_{\mu} Tμ​ T G T T_{GT} TGT​ GT:Guard Time(保护时间…

详解事件循环机制

浏览器最主要的进程 &#xff1a; 渲染主线程 如何理解JS的异步 任务没有优先级&#xff0c;但消息队列有优先级 阐述一下JS的事件循环

图书馆管理系统(2)

接下来实现系统的子菜单&#xff0c;在写一个子模块的时候&#xff0c;其他子模块先屏蔽起来&#xff0c;因为没实现&#xff0c;代码运行就通不过 屏蔽起来写上todo&#xff0c;后面(Ctrl键F)搜索&#xff0c;找todo来实现 先来实现图书管理模块 第一步&#xff0c;先要把图…