클래스 헤더 파일(.h)
#pragma once: 중복 포함을 방지하기 위해 헤더 파일의 시작 부분에 포함public, protected, private) 순서로 구성
cpp
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "YourClass.generated.h" // UHT(Unreal Header Tool) 클래스 생성 부분이므로 항상 마지막에 추가
// UHT 는 클래스,구조체,열거형에 대한 메타데이터를 생성하고 이를 기반으로 코드를 자동으로 생성한다.
// Class : 아래에 Doxygen Style 로 클래스에 대한 주석 추가 권장
/**
* @brief 이 함수는 Enemy를 특정 Location 에 생성한다.
* @details Pawn 생성 시 반드시 NullCheck을 해야 한다.
* @param SpawnLocation : 생성 위치
*/
UCLASS()
class YOURGAME_API AYourClass : public AActor
{
GENERATED_BODY()
// Function : 생성자 and 소멸자 , BeginPlay(), Tick() 등 기본적인 override 함수 ,Getter and Setter, Blueprint 관련 함수 , Notify 순으로 , 접근 한정자는 Public, Protected, Private 순으로 작성한다.
// Public
// 생성자 및 소멸자
public:
AYourClass();
virtual ~AYourClass();
// 기본적인 overried 함수
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
//Getter , Setter
public:
void GetSomething();
void SetSomething();
/* Blueprint 관련 함수는 UFUNCTION 매크로 안의
BlueprintCallable,
Blueprintimplementable,
BlueprintNativeEvent
순으로 정의한다.
나머지 특징은 임의의 순서로 최상단에 정의할 것
*/
/* 매크로 관련 용어 정리
BlueprintCallable : 블루프린트 또는 레벨 블루프린트 그래프에서 실행
BlueprintImplementableEvent: 블루프린트 또는 레벨 블루프린트 그래프에서 구현 가능
BlueprintNativeEvent: 이 함수는 블루프린트로 덮어쓰도록 디자인, But _Implementation가 붙은 함수를 추가로 선언한 뒤 코드를 작성하고
*/
public:
UFUNCTION(BlueprintCallable, Category="Action")
void PerformAction();
UFUNCTION(BlueprintImplementableEvent, Category="Action")
void PerformAction();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Gameplay")
void PerformAction();
virtual void PerformAction_Implementation();
UFUNCTION(BlueprintPure, Category="Info")
int32 GetHealth() const;
UFUNCTION(Category="Info")
int32 GetHealth() const;
// Protected 멤버 함수 (서브클래스에서 접근 가능)
protected:
void InitializeComponents();
//Private 멤버 함수
private:
void SecretFunc();
UFUNCTION()
void OnRep_ReplicatedSurvivorName();
// 노티파이 연결 함수
public:
void Run_With_Wind();
// Variable:
protected:
// Protected 멤버 변수
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
UStaticMeshComponent* MeshComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Components")
UParticleSystemComponent* ParticleSystemComponent;
private:
// Private 멤버 변수 (클래스 내부에서만 접근 가능)
UPROPERTY(EditAnywhere, Category="Stats")
int32 Health;
UPROPERTY(EditDefaultsOnly, Category="Stats")
int32 MaxHealth;
UPROPERTY(ReplicatedUsing = OnRep_ReplicatedSurvivorName)
FText ReplicatedSurvivorName;
};
@Ready To Die @Ready To Die
리플리케이트가 필요한 변수에 한해 가독성을 위해 최하단에 배치? 하는거 어떠신지
의견 남겨주세요 바로 위에 빨간색 칠해놓은 코드입니다.