【UE4】列挙型出力

この記事ではUE4.26のレコード列挙型の出力方法を使用しています。

1. 列挙型の定義と使用

  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)
{
    
    
	// ...
}

  2 番目の方法は名前空間を使用せず、変数を定義する方法は次のとおりです。

/** 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 種類に分かれます。

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

おすすめ

転載: blog.csdn.net/Bob__yuan/article/details/117855354