UE4 UE4 C++ Gameplay Abilities 的AttributeSet和GameplayEffect
UE4 UE4 C++ Gameplay Abilities 的AttributeSet和GameplayEffect
GAS参考文档
仅是个人理解,参考
AttributeSet是设置玩家属性的比如生命值、最大生命值、、、
GameplayEffect是用来对AttributeSet里的值做修改的
通过这两个东西做到:
一个加血的效果
先给玩家设置血量属性 做一个继承AttributeSet的类
// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "AbilitySystemComponent.h"
#include "AttributeSet.h"
#include "MyAttributeSet.generated.h"/*** */#define ATTRIBUTE_ACCESSORS(ClassName,PropertyName) \GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName,PropertyName) \GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName) UCLASS()
class MYGAS_API UMyAttributeSet : public UAttributeSet
{GENERATED_BODY()
public:UPROPERTY(BlueprintReadOnly)FGameplayAttributeData Health;ATTRIBUTE_ACCESSORS(UMyAttributeSet, Health)UPROPERTY(BlueprintReadOnly)FGameplayAttributeData MaxHealth;ATTRIBUTE_ACCESSORS(UMyAttributeSet, MaxHealth)UPROPERTY(BlueprintReadOnly)FGameplayAttributeData Damage;ATTRIBUTE_ACCESSORS(UMyAttributeSet, Damage)//更改之前会调用virtual void PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue) override;//更改之后virtual void PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data) override;protected:void AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute, const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty);};
// Fill out your copyright notice in the Description page of Project Settings.#include "GAS/MyAttributeSet.h"#include "GameplayEffectExtension.h"
#include "MyGAS/MyGASCharacter.h"void UMyAttributeSet::PreAttributeChange(const FGameplayAttribute& Attribute, float& NewValue)
{Super::PreAttributeChange(Attribute, NewValue);
/*GetMaxHealthAttribute() 这个要给变量加了ATTRIBUTE_ACCESSORS(UMyAttributeSet, MaxHealth) 这个宏才可以调用*/if (Attribute == GetMaxHealthAttribute()){AdjustAttributeForMaxChange(Health, MaxHealth, NewValue, GetHealthAttribute());}
}void UMyAttributeSet::PostGameplayEffectExecute(const FGameplayEffectModCallbackData& Data)
{if (Data.EvaluatedData.Attribute == GetHealthAttribute()){SetHealth(FMath::Clamp(GetHealth(), 0.0f, GetMaxHealth()));}else if (Data.EvaluatedData.Attribute == GetDamageAttribute()){float CurrentDamage = GetDamage();if (CurrentDamage > 0){SetDamage(0);SetHealth(FMath::Clamp(GetHealth() - CurrentDamage, 0.0f, GetMaxHealth()));AActor* TargetActor = Data.Target.AbilityActorInfo->AvatarActor.Get();AMyGASCharacter* TargetCharacter = Cast<AMyGASCharacter>(TargetActor);TargetCharacter->OnDamaged(CurrentDamage);}}
}void UMyAttributeSet::AdjustAttributeForMaxChange(FGameplayAttributeData& AffectedAttribute,const FGameplayAttributeData& MaxAttribute, float NewMaxValue, const FGameplayAttribute& AffectedAttributeProperty)
{UAbilitySystemComponent* AbilityComp = GetOwningAbilitySystemComponent();const float CurrentMaxValue = MaxAttribute.GetCurrentValue();if (!FMath::IsNearlyEqual(CurrentMaxValue, NewMaxValue) && AbilityComp){// Change current value to maintain the current Val / Max percentconst float CurrentValue = AffectedAttribute.GetCurrentValue();float NewDelta = (CurrentMaxValue > 0.f) ? (CurrentValue * NewMaxValue / CurrentMaxValue) - CurrentValue : NewMaxValue;AbilityComp->ApplyModToAttributeUnsafe(AffectedAttributeProperty, EGameplayModOp::Additive, NewDelta);}
}
把这个类初始化到玩家的类里面
像组件一样初始化好就行了
做血条UI
绑定血条的百分比
只有在玩家类里初始化了AttributeSet类才可以拿到
给玩家血条设置初始值
新建一个蓝图类的GameplayEffect:
设置好最大值和当前生命值
在玩家里调用就设置好了初始值
再搞个给玩家加血的GameplayEffect:
这里用到了一个曲线表格:
我们延迟一秒给玩家加50滴血
如果没有曲线表格,就在GE_Add 里面的1数字改为50
只是Level 那里填的50 就没有效果了
UE4 UE4 C++ Gameplay Abilities 的AttributeSet和GameplayEffect相关推荐
- UE4 UE4 C++ Gameplay Abilities的GameplayCue
UE4 UE4 C++ Gameplay Abilities的GameplayCue GAS参考文档 用GameplayCue 做一个玩家加血,buff效果 初始化: 加血: 加buff: buff消 ...
- UE4 UE4使用小技巧——使用上帝视角运行游戏
如下图所示: 对比:
- 接手项目,项目路径与本机UE4路径不一致以及Failed to open descriptor file ..//..//..//UE4/UE4.uproject的解决方法
删除文件夹.vs ....Binarires ...Build...Intermediate 以及项目名.sln 右键项目名.uproject generated . 打开项目名.uproje ...
- 谈谈Gameplay,以及UE4的Gameplay框架
文章目录 前言 什么是Gameplay Character Camera Control 游戏脚本 介绍脚本语言 脚本系统 UE4 Gameplay框架 介绍重要框架类 Actor类 Componen ...
- Quick #UE4 Tip (第1周 2020.12.5)
选自过去1~2周 自己所看到外文内容:https://twitter.com/search?q=%23UE4&src=recent_search_click&f=live 和各 ...
- 【UE4官方文档翻译】Unreal Engine 4 For Unity Developers (针对Unity开发者的UE4)
------------------------------------------------------------------ 说明: 本翻译是参考.修正.整理后的文档.如有错误,请 ...
- unity 线程断点时卡机_Compute Shader在Unity和UE4中的应用
该文档为学习文档,如有错误欢迎指正. 1. D3D11 Compute Shader概述 Compute Shader 是一个通用计算 Stage.它利用了GPU的并行处理器,实现大量线程并发执行.它 ...
- UE4异步编程专题 - TFunction
0. 关于这个专题 游戏要给用户良好的体验,都会尽可能的保证60帧或者更高的fps.一帧留给引擎的时间也不过16ms的时长,再除去渲染时间,留给引擎时间连10ms都不到,能做的事情是极其有限的.同步模 ...
- 【虚幻4/UE4】学习笔记01——软件介绍、安装及界面
因为工作需要,一个完全零基础的小白开始学习UE4的征途开始啦~ 一.什么是UE4 UE4是一套为游戏开发者设计和构建优先.模拟和可视化的集成工具. 简言之,做游戏的软件. 二.UE4的功能 实时逼真渲 ...
最新文章
- 用单片机测量流体流速的_曹阳等:钻井用节流阀抗冲蚀性能的实验评价
- NeurIPS 2021 | 微软研究院提出CLUES,用于NLU的少样本学习评估
- 你这么努力为什么还是做不好?
- [算法系列之二十六]字符串匹配之KMP算法
- mysql loop循环实例_MySql CURSOR+LOOP循环-使用小实例
- Taro+react开发(87):图片引入
- Linux之定时任务补充
- java 接口中的成员只有静态常量和_Java中抽象类和接口的具体区别是什么?
- npm工具运行Vue项目
- vue的自定义指令的坑
- C# 提取PDF中的表格
- PPT:人工智能在物流与供应链中的应用
- Paper 已经过时——计算机时代科学传播方式的变革
- Autosar之EB的安装与激活
- 《计算机网络》读书笔记
- 【公开课】【阿里在线技术峰会】魏鹏:基于Java容器的多应用部署技术实践
- Docker Study Note
- JS计算今天在本月第几周
- DataPipeline | 享物说产品负责人夏凯:数据驱动的用户增长实战
- 英语语法 定冠词与专有名词
热门文章
- 三星性能测试软件,三星Exynos 980 PK 骁龙765,基准测试软件中的跑分对比
- Dynamo-【NO.05】CodeBlock节点
- 闲云旅游网03(基于vue+element ui)登录注册功能开发
- Bug系列---------图片库崩溃(内存泄露)
- 2020年中国红人经济商业模式
- JVM 工作原理和流程
- php(thinkphp)在linux系统下pdf转png图片【转】
- 【摘】学佛必读的十大经典佛经
- 2022 最新 Android 基础教程,从开发入门到项目实战【b站动脑学院】学习笔记——第一章:Android开发环境搭建
- 什么是hill-climbing算法??