【UE4】枚举类型输出

本文使用 UE4.26 的记录枚举类型的输出方法

一、枚举类型定义和使用

  在 UE 中,设计一个枚举类型可以用如下方式(详见 \Engine\Source\Runtime\Engine\Classes\Engine\Blueprint.h):

/** Type of compilation. */
namespace EKismetCompileType
{
	enum Type
	{
		SkeletonOnly,
		Full,
		StubAfterFailure, 
		BytecodeOnly,
		Cpp,
	};
};

/** Compile modes. */
UENUM()
enum class EBlueprintCompileMode : uint8
{
	Default UMETA(DisplayName="Use Default", ToolTip="Use the default setting."),
	Development UMETA(ToolTip="Always compile in development mode (even when cooking)."),
	FinalRelease UMETA(ToolTip="Always compile in final release mode.")
};

  第一种是用了命名空间的,其变量的定义方式:

/** The compile type to perform (full compile, skeleton pass only, etc) */
EKismetCompileType::Type 	CompileType;

  使用方式:

if (CompileOptions.CompileType == EKismetCompileType::Full)
{
	// ...
}

  第二种没有用命名空间,变量定义方式:

/** The mode that will be used when compiling this class. */
UPROPERTY(EditAnywhere, Category=ClassOptions, AdvancedDisplay)
EBlueprintCompileMode CompileMode;

  使用方式:

if (OwningBP->CompileMode != EBlueprintCompileMode::Default))
{
	// ...
}

  两种方式使用区别不大,输出方式也是一样的,分为两种:1. 输出整型,2. 输出字符串。

二、枚举类型输出

2.1 整型输出

  枚举类型本身就是整型数据,所以直接按整型输出即可:

UE_LOG(LogTemp, Error, TEXT("Current is %d"), EBlueprintCompileMode::Development);

  可以得到输出 LogTemp: Error: Current is 1

2.2 字符串输出

  枚举类型多的时候,输出一个 5 完全不知道是哪个,所以肯定还是直接输出名字是最直接的:

EBlueprintCompileMode const ETest = EBlueprintCompileMode::Development;
UEnum* const CompileModeEnum = StaticEnum<EBlueprintCompileMode>();
if (CompileModeEnum)
{
	UE_LOG(LogTemp, Error, TEXT("Current is %s"),
		*CompileModeEnum->GetDisplayNameTextByValue(static_cast<uint8>(ETest)).ToString());
}

  可以得到输出 LogTemp: Error: Current is Development

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值