基于C++代码的UE4学习(二十八)——枚举类与结构体

先说枚举类,概念不进行解释。

1 UENUM(BlueprintType)
2 enum Tree {
3     Tree_1,
4     Tree_2,
5     Tree_3,
6     Tree_4,
7     Tree_5
8 };
1 AMyActor::AMyActor() {
2     mode = Tree_3; //将Tree_3设置为默认值
3 
4     FString s = FString::Printf(TEXT("the enum tree default value is: %d"), mode);
5     GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Red,s);
6 }

再看结构体

 1 USTRUCT(BlueprintType)
 2 
 3 struct FMyStruct  //F很重要,不能不写
 4 {
 5     GENERATED_USTRUCT_BODY()  //BODY这句话也很重要
 6 
 7     UPROPERTY(EditAnywhere,BlueprintReadWrite,Category = "Struct | Properties")
 8     FString name;
 9     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct | Properties")
10     int id;
11     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Struct | Properties")
12     bool isGood;
13 };

 

猜你喜欢

转载自www.cnblogs.com/dlak/p/13390001.html