【UE4 C++ 基礎知識】<4> 枚舉 Enum、結構體 Struct


枚舉

  • UENUM宏搭配BlueprintType可以將枚舉暴露給藍圖,不使用的話,僅能在C++使用
//定義一個原生enum class
enum class EMyType 
{
	Type1,
	Type2,
	Type3,
};

UENUM(BlueprintType)
enum class ECurrentState : uint8
{
	Idle UMETA(DisplayName="空閑"),
	Attack UMETA(DisplayName="攻擊"),
	Roll UMETA(DisplayName="翻滾"),
	Dead UMETA(DisplayName="死亡"),
};

UPROPERTY(EditAnywhere,BlueprintReadWrite)
	ECurrentState MyCurrentState UMETA(DisplayName = "當前狀態");

image

結構體

  • BlueprintType可以將枚舉暴露給藍圖
//結構體
USTRUCT(BlueprintType)
struct FMyStruct
{
    GENERATED_BODY()

    // 暴露給藍圖
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Test Variables")
    int32 MyIntegerMemberVariable;

    // 不暴露給藍圖
    int32 NativeOnlyMemberVariable;

    // 藍圖圖表無法訪問此UObject指針,但是指針對UE4的反射、智能指針和垃圾回收系統可見。
    UPROPERTY()
    UObject* SafeObjectPointer;
};

UPROPERTY(EditAnywhere,BlueprintReadWrite)
	FMyStruct MyStruct;

image

  • 繼承FTableRowBase之后可以用於DataTable
struct FInventoryItemInfo : public FTableRowBase
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FString ItemName UMETA(DisplayName="名稱");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 index UMETA(DisplayName="編號");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bCanStaking UMETA(DisplayName="可否疊加");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		int32 Count UMETA(DisplayName="數量");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UTexture2D* Icon UMETA(DisplayName="圖標");

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TSubclassOf<AActor> ItemClass;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		USkeletalMesh* SkeletalMesh;
};

UPROPERTY(EditAnywhere,BlueprintReadWrite)
		FInventoryItemInfo EmptyItem;

image

參考

結構體


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM