当前位置: 首页 > article >正文

【虚幻C++笔记】枚举UENUM、结构体USTRUCT

目录

  • 枚举(UENUM)
    • 第一种:使用命名空间
    • 第二种:继承uint8通过申明class类别名来替代
  • 结构体(USTRUCT)

枚举(UENUM)

第一种:使用命名空间

UENUM(BlueprintType)
namespace MyEnumType
{
    enum MyCustomEnum
    {
       Type1,// 或者使用带 DisplayName别名 ==> Enum1 UMETA(DisplayName = "Type1"),
       Type2,
       Type3,
    }
}
//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyEnumType")
TEnumAsByte<MyEnumType::MyCustomType> MyEnumType;

第二种:继承uint8通过申明class类别名来替代

UENUM(BlueprintType)
enum class MyEnumType2 : uint8
{
  Enum1 UMETA(DisplayName = "Type1"),
  Enum2 UMETA(DisplayName = "Type2"),
  Enum3 UMETA(DisplayName = "Type3"),
  Enum4 UMETA(DisplayName = "Type4"),
};

//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyEnumType2")
TEnumAsByte<MyEnumType2> MyEnumType2;

结构体(USTRUCT)

// 暴露给蓝图
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="MyStructType")
int32 Age;
// 不暴露给蓝图
int32 Age;
// 蓝图图表无法访问此UObject指针,但是指针对UE的反射、智能指针和垃圾回收系统可见。
UPROPERTY()
UObject* ObjectPointer;
//注意,定义结构体名称前要加F前缀,不然编译不通过。
USTRUCT(BlueprintType)
struct FMyCustomStruct
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString ID;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString Name;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  int32 Age;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  float Height;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  bool IsMan;
};

//结构体创建数据表格,需继承FTableRowBase
USTRUCT(BlueprintType)
struct FMyCustomStruct:public FTableRowBase
{
  GENERATED_USTRUCT_BODY()

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString ID;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  FString Name;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  int32 Age;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  float Height;
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyStructType")
  bool IsMan;
};
//在蓝图中声明
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "MyExposeOnSpawn", meta = (ExposeOnSpawn = "ExposeOnSpawnValue"))
FMyCustomStruct MyCustomStruct;


http://www.kler.cn/a/587856.html

相关文章:

  • 基于CPU使用paddlex OCR识别图片内容
  • 《 线程池项目:线程池背景知识与整体架构梳理》
  • Postman中Authorization和Headers的区别
  • 【软考网工-实践篇】DHCP 动态主机配置协议
  • 【Vue列表渲染中key与数据绑定的核心问题解析】
  • 小程序渲染之谜:如何解决“加载中...”不消失的 Bug(glass-easel)
  • SpringMVC (二)请求处理
  • docker Mysql主从配置
  • 【设计模式】《设计模式:可复用面向对象软件的基础》:设计模式怎样解决设计问题?
  • Vue 系列之:ref、reactive、toRef、toRefs
  • 合并pull request的过程
  • 色彩重生:基于 Retinex 理论的 UR2P-Dehaze 去雾增强器解析
  • PyTorch 深度学习实战(13):Proximal Policy Optimization (PPO) 算法
  • 面试常见概念区分:并发与并行、同步与异步、阻塞与非阻塞、线程同步与互斥
  • 设计模式之装饰器模式:原理、实现与应用
  • 阿里云服务器购买及环境搭建宝塔部署springboot和vue项目
  • 论文阅读笔记:Deep Unsupervised Learning using Nonequilibrium Thermodynamics
  • 在Spring Boot项目中接入DeepSeek深度求索,感觉笨笨的呢
  • 【设计模式】从事件驱动到即时更新:掌握观察者模式的核心技巧
  • 深入探究 HTML 框架:多页面同窗口显示的奥秘