Replicated

[Drag Down] 게임 모드 및 컨트롤러 분리 본문

언리얼 엔진/Drag Down

[Drag Down] 게임 모드 및 컨트롤러 분리

라구넹 2025. 5. 19. 02:52

대기방이랑 실 게임 플레이도 게임 모드랑 컨트롤러 분리하는게 훨씬 나을 것 같다

정확힌 컨트롤러 분리를 위해 게임 모드도 새로 만든다

 

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

#pragma once

#include "CoreMinimal.h"
#include "Player/DDPlayerController.h"
#include "DDWatingPlayerController.generated.h"

/**
 * 
 */
UCLASS()
class DRAGDOWN_API ADDWatingPlayerController : public ADDPlayerController
{
	GENERATED_BODY()
	
public:
	virtual void BeginPlay() override;

// Ready Setting
public:
	UFUNCTION(BlueprintCallable)
	void SetUserReady(bool bIsReady);

protected:
	void HandleSetUserReady(bool bIsReady);

	UFUNCTION(Server, Reliable)
	void ServerSetUserReady(bool bIsReady);
};


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


#include "Player/DDWatingPlayerController.h"
#include "Game/DDGameState.h"

void ADDWatingPlayerController::BeginPlay()
{
	Super::BeginPlay();

	FInputModeGameAndUI InputMode;
	SetInputMode(InputMode);
	bShowMouseCursor = true;
}

void ADDWatingPlayerController::SetUserReady(bool bIsReady)
{
	if (HasAuthority())
	{
		HandleSetUserReady(bIsReady);
	}
	else
	{
		ServerSetUserReady(bIsReady);
	}
}

void ADDWatingPlayerController::HandleSetUserReady(bool bIsReady)
{
	if (GameState)
	{
		GameState->SetPlayerReady(PlayerIdx, bIsReady);
	}
}

void ADDWatingPlayerController::ServerSetUserReady_Implementation(bool bIsReady)
{
	HandleSetUserReady(bIsReady);
}

실 게임 플레이 시엔 Ready 상태 필요하지도 않은데 사용하게 되어 상속해서 내렸다