Sound Manager 개요
Sound Manager는 게임에서 오디오 리소스를 관리·로드·재생하는 핵심 모듈입니다.
다음과 같은 기능을 제공합니다:
•
사운드를 논리적인 그룹으로 관리
•
재생 제어(재생, 정지, 일시 정지, 재개)
•
그룹 및 개별 사운드 수준에서 볼륨·음소거 제어
•
재생 우선순위 설정 및 제한 시 동작 정의
•
페이드 인·아웃 지원
•
비동기 사운드 로딩과 이벤트 알림
아키텍처
•
Game Framework 전체에서 사용하는 모듈 아키텍처 패턴을 따릅니다.
•
GameFrameworkModule을 상속받고 GameFrameworkEntry에 의해 관리됩니다.
•
사운드 리소스 로드는 Resource Manager에 의존합니다.
•
플랫폼별 구현은 Helper 인터페이스로 추상화됩니다.
핵심 구성 요소
1. Sound Group
사운드를 그룹별로 묶어 제어합니다.
•
Name: 그룹의 고유 이름
•
AvoidBeingReplacedBySamePriority: 동일 우선순위 사운드로 대체 여부
•
Mute: 그룹 전체 음소거 여부
•
Volume: 그룹 전체 볼륨(0.0~1.0)
•
SoundAgentCount: 해당 그룹의 사운드 에이전트 수
2. Sound Agent
•
실제 사운드 재생을 담당합니다.
•
각 그룹은 여러 Sound Agent를 가질 수 있으며, 이는 동시에 재생 가능한 사운드 수를 의미합니다.
•
플랫폼별 Agent Helper를 통해 생성됩니다.
사용 방법
1. 초기화
ISoundManager soundManager = GameFrameworkEntry.GetModule<ISoundManager>();
soundManager.SetResourceManager(resourceManager);
soundManager.SetSoundHelper(soundHelper);
C#
복사
2. 사운드 그룹 생성
soundManager.AddSoundGroup("Music", musicGroupHelper);
soundManager.AddSoundGroup("SFX", true, false, 0.8f, sfxGroupHelper);
C#
복사
3. 사운드 에이전트 추가
soundManager.AddSoundAgentHelper("Music", musicAgentHelper);
for (int i = 0; i < 10; i++)
{
soundManager.AddSoundAgentHelper("SFX", CreateSoundAgentHelper());
}
C#
복사
4. 사운드 재생
// 기본 재생
int serialId = soundManager.PlaySound("explosion.wav", "SFX");
// 파라미터 사용
PlaySoundParams playSoundParams = PlaySoundParams.Create();
playSoundParams.Priority = 100;
playSoundParams.Loop = true;
playSoundParams.VolumeInSoundGroup = 0.5f;
playSoundParams.FadeInSeconds = 2f;
playSoundParams.SpatialBlend = 1f;
int musicId = soundManager.PlaySound("background.mp3", "Music", playSoundParams);
C#
복사
5. 재생 제어
soundManager.StopSound(serialId);
soundManager.StopSound(serialId, 3.0f);
soundManager.PauseSound(serialId);
soundManager.ResumeSound(serialId);
soundManager.StopAllLoadedSounds();
C#
복사
이벤트 시스템
•
PlaySoundSuccess – 사운드가 정상적으로 재생 시작
•
PlaySoundFailure – 로드 또는 재생 실패
•
PlaySoundUpdate – 로딩 진행률 업데이트
•
PlaySoundDependencyAsset – 사운드 종속 리소스 로드 시 호출
soundManager.PlaySoundSuccess += (sender, e) =>
{
Debug.Log($"Sound {e.SerialId} ({e.SoundAssetName}) started!");
};
C#
복사
리소스 시스템 연동
•
Sound Manager는 사운드 재생 요청 시 Resource Manager를 통해 리소스를 로드합니다.
•
로드 완료 후 Sound Agent를 생성해 재생을 시작합니다.
프레임워크 내 위치
•
Sound Manager는 Entity Manager, UI Manager와 함께 핵심 모듈입니다.
•
세 모듈 모두 Resource Manager에 의존하며, 그룹 기반 구조를 사용합니다.
일반 사용 사례
배경음악
soundManager.AddSoundGroup("Music", false, false, 0.8f, musicGroupHelper);
soundManager.AddSoundAgentHelper("Music", musicAgentHelper);
PlaySoundParams musicParams = PlaySoundParams.Create();
musicParams.Loop = true;
musicParams.FadeInSeconds = 2.0f;
int musicId = soundManager.PlaySound("background.mp3", "Music", musicParams);
C#
복사
효과음
soundManager.AddSoundGroup("SFX", true, false, 1.0f, sfxGroupHelper);
for (int i = 0; i < 5; i++)
{
soundManager.AddSoundAgentHelper("SFX", CreateSfxAgentHelper());
}
soundManager.PlaySound("explosion.wav", "SFX");
soundManager.PlaySound("footstep.wav", "SFX");
C#
복사
UI 사운드
soundManager.AddSoundGroup("UI", false, false, 0.5f, uiSoundGroupHelper);
soundManager.AddSoundAgentHelper("UI", uiSoundAgentHelper);
soundManager.PlaySound("button_click.wav", "UI");
soundManager.PlaySound("menu_open.wav", "UI");
C#
복사
결론
Game Framework의 Sound Manager는 그룹·에이전트 기반 오디오 시스템을 제공해, 세밀한 사운드 제어와 리소스 관리 통합을 가능하게 합니다. 이를 통해 다양한 오디오 환경에서 유연하고 강력한 재생 기능을 구현할 수 있습니다.