언리얼 개인 프로젝트/언리얼엔진C++ 독학(이득우)

2.액터의 설계

현구구 2022. 3. 3. 13:37

Fountain.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Fill out your copyright notice in the Description page of Project Settings.
 
#pragma once
 
#include "EngineMinimal.h"
#include "GameFramework/Actor.h"
#include "Fountain.generated.h"
 
UCLASS()
class ARENABATTLE_API AFountain : public AActor
{
    GENERATED_BODY()
    
public:    
    // Sets default values for this actor's properties
    AFountain();
 
protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
 
public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;
 
    UPROPERTY(VisibleAnywhere)//객체관리 매크로
    UStaticMeshComponent* Body; // 분수의 몸체 선언
 
    UPROPERTY(VisibleAnywhere) //VisibleAnywhere 언리얼엔진 디테일윈도우에서 편집할 수 있게 설정
    UStaticMeshComponent* Water; // 분수 물 선언
 
    UPROPERTY(VisibleAnywhere)
    UPointLightComponent* Light;
 
    UPROPERTY(VisibleAnywhere)
    UParticleSystemComponent* Splash;
};
 
cs

Fountain.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Fill out your copyright notice in the Description page of Project Settings.
 
 
#include "Fountain.h"
 
// Sets default values
AFountain::AFountain() //생성자
{
     // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;
    Body = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BODY")); // h 파일에서 선언한 Body를 Fountain.cpp 생성자에서 생성
    Water = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("WATER"));
    Light = CreateDefaultSubobject<UPointLightComponent>(TEXT("Light"));
    Splash = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("SPLASH"));
 
    RootComponent = Body; //몸체는 Body
    Water->SetupAttachment(Body); // Water 는 Body에 상속시킨다
    Light->SetupAttachment(Body);
    Splash->SetupAttachment(Body);
 
    Water->SetRelativeLocation(FVector(0.0f, 0.0f, 135.0f)); //Fountain 엑터 안에서 Water의 위치 설정
    Light->SetRelativeLocation(FVector(0.0f, 0.0f, 195.0f));
    Splash->SetRelativeLocation(FVector(0.0f, 0.0f, 195.0f));
 
    static ConstructorHelpers::FObjectFinder<UStaticMesh> //스태틱매시의 위치를 불러옴
        SM_BODY(TEXT("/Game/InfinityBladeGrassLands/Environments/Plains/Env_Plains_Ruins/StaticMesh/SM_Plains_Castle_Fountain_01.SM_Plains_Castle_Fountain_01"));
    if (SM_BODY.Succeeded())//스태틱매시를 위 경로에서 불러오는데 성공했다면 
    {
        Body->SetStaticMesh(SM_BODY.Object); //Body에는 SM_BODY 대입 후 고정
    }
 
    static ConstructorHelpers::FObjectFinder<UStaticMesh> //Water 불러오기
        SM_WATER(TEXT("/Game/InfinityBladeGrassLands/Effects/FX_Meshes/Env/SM_Plains_Fountain_02.SM_Plains_Fountain_02"));
    if (SM_WATER.Succeeded())
    {
        Water->SetStaticMesh(SM_WATER.Object);
    }
 
    static ConstructorHelpers::FObjectFinder<UParticleSystem> //파티클 불러옴
        PS_SPLASH(TEXT("/Game/InfinityBladeGrassLands/Effects/FX_Ambient/Water/P_Water_Fountain_Splash_Base_01.P_Water_Fountain_Splash_Base_01"));
    if (PS_SPLASH.Succeeded())//스태틱매시를 위 경로에서 불러오는데 성공했다면 
    {
        Splash->SetTemplate(PS_SPLASH.Object);
    }
}
 
// Called when the game starts or when spawned
void AFountain::BeginPlay()
{
    Super::BeginPlay();
    
}
 
// Called every frame
void AFountain::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
 
}
 
 
cs