Replicated

[Drag Down] 메뉴 만들기 #1 커스텀 UserSetting, 메뉴 토글 본문

언리얼 엔진/Drag Down (캡스톤 디자인)

[Drag Down] 메뉴 만들기 #1 커스텀 UserSetting, 메뉴 토글

라구넹 2025. 4. 23. 12:21

이 세팅이랑 DLSS 세팅할 거다

UGameUserSettings상속해서 클래스 만들어주고

 

DefaultEngine.ini에 설정 추가

이래야 기본 세팅이 DDUserSettings로 변경됨

 

GameUserSettings만으로도 잘 작동할 것 같긴 하지만, GameInstanceSubssytem으로 래핑하는게 더 유연할 것 같다.

 

void UDDGameSettingSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
	Super::Initialize(Collection);

	UserSettings = Cast<UDDUserSettings>(GEngine->GetGameUserSettings());

	if ( UserSettings )
	{
		UE_LOG(LogDD, Log, TEXT("UserSettings Found"));
	}
	else
	{
		UE_LOG(LogDD, Error, TEXT("UserSettings not Found"));
	}
}

발견! 일단 ini 설정은 잘 된 거 같다

 

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameUserSettings.h"
#include "DDUserSettings.generated.h"

/**
 * 
 */
UCLASS()
class DRAGDOWN_API UDDUserSettings : public UGameUserSettings
{
	GENERATED_BODY()
	
public:
	UDDUserSettings();

	virtual void ApplySettings(bool bForce = false) override;

	UFUNCTION(BlueprintCallable)
	FORCEINLINE float GetBGMVolume() { return BGMVolume; }

	UFUNCTION(BlueprintCallable)
	void SetBGMVolume(float InBGMVolume);

	UFUNCTION(BlueprintCallable)
	FORCEINLINE float GetSFXVolume() { return SFXVolume; }

	UFUNCTION(BlueprintCallable)
	void SetSFXVolume(float InSFXVolume);

protected:
	UPROPERTY(Config)
	float BGMVolume;

	UPROPERTY(Config)
	float SFXVolume;
};

커스텀 GameUserSettings이다

일단 기본 클래스에서 그래픽 요소는 제공을 하고, 거기에 사운드 틀만 짜놨다

 

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


#include "Setting/DDUserSettings.h"

UDDUserSettings::UDDUserSettings()
{
	BGMVolume = 1.0f;
	SFXVolume = 1.0f;

	LoadConfig();
}

void UDDUserSettings::ApplySettings(bool bForce)
{
	Super::ApplySettings(bForce);

	SetBGMVolume(BGMVolume);
	SetSFXVolume(SFXVolume);
}

void UDDUserSettings::SetBGMVolume(float InBGMVolume)
{
	BGMVolume = FMath::Clamp(InBGMVolume, 0.0f, 1.0f);
	SaveConfig();
}

void UDDUserSettings::SetSFXVolume(float InSFXVolume)
{
	SFXVolume = FMath::Clamp(InSFXVolume, 0.0f, 1.0f);
	SaveConfig();
}

SaveConfig, LoadConfig시 DefaultEngine.ini에서 알아서 할 거다

 

이제 다음은 UI 인풋 처리이다

탭을 누르면 메뉴가 나타나고, 사라지고 하도록 할 것이다

게임 패드도 설정해주자

 

// Normal Widget
public:
	void ToggleMenu();
	void OpenMenu();
	void CloseMenu();

	// UMG 위젯 클래스 (블루프린트에서 설정)
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UI")
	TSubclassOf<class UUserWidget> MenuWidgetClass;

	UPROPERTY()
	TObjectPtr<class UUserWidget> MenuWidget;

	bool bIsMenuOpen;
};

void ADDPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	InputComponent->BindAction("OpenMenu", IE_Pressed, this, &ADDPlayerController::ToggleMenu);
}

void ADDPlayerController::ToggleMenu()
{
	if (bIsMenuOpen) CloseMenu();
	else OpenMenu();
}

void ADDPlayerController::OpenMenu()
{
	if (MenuWidgetClass == nullptr) return;
	
	if ( MenuWidget == nullptr )
	{
		MenuWidget = CreateWidget(this, MenuWidgetClass);
	}
	
	MenuWidget->AddToViewport(100);

	FInputModeGameAndUI UIInputMode; 
	UIInputMode.SetWidgetToFocus(MenuWidget->TakeWidget());
	SetInputMode(UIInputMode);
	bShowMouseCursor = true;
	bIsMenuOpen = true;
}

void ADDPlayerController::CloseMenu()
{
	if ( MenuWidget )
	{
		MenuWidget->RemoveFromViewport();
	}

	FInputModeGameOnly InputMode;
	SetInputMode(InputMode);
	bShowMouseCursor = false;
	bIsMenuOpen = false;
}

FName에 해당하는 인풋이 들어오면 플레이어 컨트롤러가 감지해서 메뉴를 띄워주거나, 닫는 코드이다