개인프로젝트

[Unreal_C++_DarkSoul]#3_기능 구현, Custom Structure, Custom Enumeration

Hardii2 2022. 11. 23. 11:03

 

[Unreal_C++_DarkSoul]#3_Custom Structure, Custom Enumeration

 

Unreal C++ 개발 중 "커스텀 구조체 클래스와 커스텀 열거형 클래스"에 대한 내용입니다.

포트폴리오 진행 사항을 기록하기 위한 포스팅입니다.

 

 


 

Overview

 

  1. 임의의 Actor 클래스를 생성합니다.
  2. Actor 클래스의 헤더 파일에 사용자 정의 구조체 클래스와 열거형 클래스를 작성합니다.
  3. 각 타입의 클래스는 Unreal Editor에 Reflection 하기 위해 "USTRUCT()"와 "UENUM()"을 선언합니다.

 

Custom Enum Class

1. Custom_Enums.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Custom_Enums.generated.h"

UCLASS()
class DARKSOUL_API ACustom_Enums : public AActor
{
	GENERATED_BODY()
};

// 0. State Enums					********************************************

UENUM(BlueprintType)
enum class EStateType : uint8
{
	E_Idle = 0 			UMETA(DisplayName = "Idle"),
	E_Attacking 		UMETA(DisplayName = "Attacking"),
	E_Skilling			UMETA(DisplayName = "Skilling"),
	E_Guarding			UMETA(DisplayName = "Guarding"),
	E_Stumbling 		UMETA(DisplayName = "Stumbling"),
	E_Rolling 			UMETA(DisplayName = "Rolling"),
	E_Backstsepping 	UMETA(DisplayName = "Backstepping")
};

UENUM(BlueprintType)
enum class EComboType : uint8
{
	E_ComboType_1 = 0 	UMETA(DisplayName = "First Combo Type"),
	E_ComboType_2 		UMETA(DisplayName = "Second Combo Type"),
};

// 1. Player State Enums			********************************************

UENUM(BlueprintType)
enum class EPlayerCombatType : uint8
{
	E_Unarmed = 0 	UMETA(DisplayName = "Unarmed"),
	E_Fighter 		UMETA(DisplayName = "Fighter"),
	E_SwordMaster 	UMETA(DisplayName = "Sword Master"),
	E_AxeMaster 	UMETA(DisplayName = "Axe Master"),
	E_Samurai		UMETA(DisplayName = "Samurai"),
	E_Warrior		UMETA(DisplayName = "Warrior"),
	E_Wizard 		UMETA(DisplayName = "Wizard"),
	E_Gunner 		UMETA(DisplayName = "Gunner"),
};

// 3. Weapon Type				********************************************

UENUM(BlueprintType)
enum class EWeaponType : uint8
{
	E_Sword = 0			UMETA(DisplayName = "Sword"),
	E_Axe				UMETA(DisplayName = "Axe"),
	E_Fist				UMETA(DisplayName = "Fist"),
	E_Katana			UMETA(DisplayName = "Katana"),
	E_SwordAndShield	UMETA(DisplayName = "SwordAndShield"),
	E_CastleKnight_Axe	UMETA(DisplayName = "CastleKnight_Axe")
};

// 4. Attribute Type			********************************************

UENUM(BlueprintType)
enum class EAttributeType : uint8
{
	E_Steel = 0			UMETA(DisplayName = "Steel"),
	E_Fire				UMETA(DisplayName = "Fire"),
	E_Ice				UMETA(DisplayName = "Ice"),
	E_Electric			UMETA(DisplayName = "Electric"),
	E_Dark				UMETA(DisplayName = "Dark")
};

// 5. Enmey Type				********************************************

UENUM(BlueprintType)
enum class EEnemyType : uint8
{
	E_None = 0				UMETA(DisplayName = "None"),
	E_CastleKnight			UMETA(DisplayName = "Castle Knight"),
};

 

Details

  1. "UENUM()"을 통해 Unreal Editor에서도 활용 가능한 열거형 클래스를 선언합니다.
  2. 이때, "enum"이 아니라 "enum class"를 선언해야합니다.
  3. "UMETA()"를 통해 메타데이터를 작성합니다.

 

Custom Structure Class

1. Custom_Structs.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

#include "Custom_Enums.h"
#include "GameFramework/Actor.h"
#include "Engine/DataTable.h"
#include "Animation/AnimMontage.h"
#include "Particles/ParticleSystem.h"

#include "Custom_Structs.generated.h"

UCLASS()
class DARKSOUL_API ACustom_Structs : public AActor
{
	GENERATED_BODY()
};

// 0. Weapon				******************************************************

USTRUCT(Atomic, BlueprintType)
struct FNoComboAnimInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UAnimMontage* AnimMontage;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName StartSection;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float PlayRate;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool CanMove;
};

USTRUCT(Atomic, BlueprintType)
struct FComboAnimInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UAnimMontage* AnimMontage;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName StartSection;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float PlayRate;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool CanMove;
};

USTRUCT(Atomic, BlueprintType)
struct FSkillAnimInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UAnimMontage* AnimMontage;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName StartSection;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float PlayRate;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool CanMove;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool bRadial;		// 단일 스킬 + 광역 스킬
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float SphereRadius;	// 광역 스킬 범위
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float BaseDamage;	// 스킬 데미지	
	// TODO	:	Hit Effect + Death Effect
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UParticleSystem* AttackEffect;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UParticleSystem* ImpactEffect;
};

// 1. Statics				******************************************************

USTRUCT(Atomic, BlueprintType)
struct FSpecInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float MaxHealth;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float AttackPower;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float DefensePower;
};

// 2. Power					******************************************************

USTRUCT(Atomic, BlueprintType)
struct FPowerInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		EWeaponType Weapon;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		EAttributeType Attribute;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float AttackPower;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float AttackRate = 1.f;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float CriticalCount = 10.f;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float CriticalMinRate = 1.f;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float CriticalMaxRate = 5.f;

};

// 3. PlayerCharacter		******************************************************

USTRUCT(Atomic, BlueprintType)
struct FCommonAnimInfo : public FTableRowBase
{
public:
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UAnimMontage* AnimMontage;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FName StartSection;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float PlayRate;
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool CanMove;
	// TODO	:	Hit Effect + Death Effect
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UParticleSystem* Effect;
};

 

Details

  1. "USTRUCT()"를 통해 Unreal Editor에 Reflection 합니다.
  2. "FTableRowBase"를 Public 상속하여, Unreal Editor의 Data Table 자료형과 상호작용합니다!
  3. Unreal이 제공하는 Data Table 자료형을 구조체와 함께 활용하는 방법은 추후에 살펴보겠습니다.