팀프로젝트, 팀프로젝트 GDD작성, 알고리즘 1문제
USaveGame은 "저장 전용 데이터 상자"이고, 게임을 껐다 켜도 남아야 하는 저장 파일이다.
UOutGameSettingsSaveGame* SaveData =
Cast<UOutGameSettingsSaveGame>(
UGameplayStatics::CreateSaveGameObject(UOutGameSettingsSaveGame::StaticClass())
);
SaveData->MasterVolume = MasterVolume;
SaveData->MusicVolume = MusicVolume;
SaveData->SFXVolume = SFXVolume;
SaveData->UIVolume = UIVolume;
UGameplayStatics::SaveGameToSlot(SaveData, TEXT("Settings"), 0);
if (UGameplayStatics::DoesSaveGameExist(TEXT("Settings"), 0))
{
UOutGameSettingsSaveGame* SaveData =
Cast<UOutGameSettingsSaveGame>(
UGameplayStatics::LoadGameFromSlot(TEXT("Settings"), 0)
);
if (IsValid(SaveData))
{
MasterVolume = SaveData->MasterVolume;
MusicVolume = SaveData->MusicVolume;
SFXVolume = SaveData->SFXVolume;
UIVolume = SaveData->UIVolume;
}
}
SlotName은 저장 파일 이름이고, UserIndex는 보통 PC 싱글 프로젝트면 0 사용
SaveGame에 저장 해야할 것들은 다양하다. 모든 데이터를 저장하는 것보단 볼륨 설정, 마우스 감도, 클리어 기록, 컨텐츠UnLock 여부 등 게임 진행상황을 저장해야하고 PlayerController 포인터라던가 맵에 배치된 Actor 포인터라던가 이런 일시적인 런타임 객체들을 저장하기에는 애매하다.
이건 특정 SoundClass의 볼륨을 런타임에 덮어쓰는 작업이다.
전체적인 흐름은 다음과 같다.
SoundClass
SoundMix-> 배경음악 -> SC_Music
-> 총소리/효과음 -> SC_SFX
-> 버튼 클릭음 -> SC_UI
이렇게 분리해서 클래스를 지정해둔다.
UGameplayStatics::SetSoundMixClassOverride(
this,
SettingsSoundMix,
MusicSoundClass,
MusicVolume,
1.0f,
0.1f,
false
);
이렇게 UI와 연결해서 Setting 해두면 전체적인 소리 밸런스를 조정하고싶으면 SC_Master로 전체적으로 변경하면 된다.