- GameMode : 게임의 규칙
- Pawn : 플레이어가 조종하는 Actor
AABGameMode, AABPawn C++ 클래스를 생성한다
GameMode
AABGameMode::AABGameMode()
{
// AABGameMode의 기본 PawnClass를 AABPawn::StaticClass로 지정
DefaultPawnClass = AABPawn::StaticClass();
// ...
- PlayerController : 캐릭터 Pawn의 컨트롤을 담당, GameMode 클래스에서 생성한다.
AABPlayerController 클래스 생성
AABGameMode::AABGameMode()
{
DefaultPawnClass = AABPawn::StaticClass();
PlayerControllerClass = AABPlayerController::StaticClass();
}
캐릭터가 생성시 GameMode에서 PostLogin
가 호출되며 로그로 찍어서 확인해 보고싶다면
void AABGameMode::PostLogin(APlayerController* NewPlayer)
{
ABLOG(Warning, TEXT("PostLogin Begin"));
Super::PostLogin(NewPlayer);
ABLOG(Warning, TEXT("PostLogin End"));
}
PlaterController
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "ArenaBattle.h"
#include "GameFramework/PlayerController.h"
#include "ABPlayerController.generated.h"
/**
*
*/
UCLASS()
class ARENABATTLE_API AABPlayerController : public APlayerController
{
GENERATED_BODY()
public:
virtual void PostInitializeComponents() override;
virtual void Possess(APawn* aPawn) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "ABPlayerController.h"
void AABPlayerController::PostInitializeComponents()
{
Super::PostInitializeComponents();
ABLOG_S(Warning);
}
void AABPlayerController::Possess(APawn *aPawn)
{
ABLOG_S(Warning);
Super::Possess(aPawn);
}
Pawn
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "ArenaBattle.h"
#include "GameFramework/Pawn.h"
#include "ABPawn.generated.h"
UCLASS()
class ARENABATTLE_API AABPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AABPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
virtual void PostInitializeComponents() override;
virtual void PossessedBy(AController* NewController) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#include "ABPawn.h"
// Sets default values
AABPawn::AABPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AABPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AABPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AABPawn::PostInitializeComponents()
{
Super::PostInitializeComponents();
ABLOG_S(Warning);
}
void AABPawn::PossessedBy(AController* NewController)
{
ABLOG_S(Warning);
Super::PossessedBy(NewController);
}
// Called to bind functionality to input
void AABPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}