SoundSubsystem - osy9611/ProjectPT GitHub Wiki
Unity์ SoundManager ๊ฐ๋จ ์ ๋ฆฌ
-
Unity์์๋ SoundManager๋ฅผ ๊ตฌํํด์ ์ฌ์ด๋ ์ฌ์ ๋ฐ ๋ฆฌ์์ค ๊ด๋ฆฌ๋ฅผ ์ํด์ ์์ฑํ๋ค.
-
์ค์์์ ์ฌ์ด๋ ์ ์ด๋ฅผ ํตํด ์ ์ง๋ณด์๋ฅผ ์ฉ์ดํ๊ธฐ ์ํด์ ์ฌ์ฉํ๋ค.
-
์ผ๋ถ ์ฝ๋
public void Play(AudioClip clip, eSound type = eSound.FX, float pitch = 1.0f) { if (clip == null) return; if (type == eSound.Bgm) { AudioSource audioSource = audioSources[(int)eSound.Bgm]; if (audioSource.isPlaying) audioSource.Stop(); audioSource.pitch = pitch; audioSource.clip = clip; audioSource.Play(); } else { AudioSource audioSource = audioSources[(int)type]; audioSource.pitch = pitch; audioSource.PlayOneShot(clip); } }
Unreal์์ ๊ตฌํํ SoundSubsystem
-
Unreal์์๋ SoundSubsystem์ ๊ตฌํํด์ ํ๋์ Subsystem์์ ์ฌ์ด๋๋ฅผ ์ ์ดํ๋ค.
-
Unity SoundManager์์๋ ๊ฐ ํ์ ์ ๋ฐ๋ผ ์ฌ์ด๋๋ฅผ ์ฌ์ํ์๋ค. ์ด๋ฒ ํ๋ก์ ํธ์์๋ ์ด์ ๋์ผํ๊ฒ ๊ตฌํ์ ์งํํจ
- BGM : ๊ฒ์์ ๋ฐฐ๊ฒฝ์์ ์ ์ดํ๊ธฐ ์ํ ํ์
- SFX : ์ฌ์ด๋ ํน์ ํจ๊ณผ๋ฅผ ์ ์ดํ๊ธฐ ์ํ ํ์
- Voice : ์บ๋ฆญํฐ ๋ชฉ์๋ฆฌ ์ฌ์ด๋๋ฅผ ์ ์ดํ๊ธฐ ์ํ ํ์
-
Unreal์์๋ ๊ฐ ์ฌ์ด ์ ํ๋๋ฉด AudioComponent์ ์ ํ๋ World๋ฅผ ๋ฑ๋ก ํด์ค์ผํ๋ค.
-
Unreal์ World ๋จ์๋ก ์ค๋์ค ์ปดํฌ๋ํธ๊ฐ ๊ด๋ฆฌ๋๊ธฐ ๋๋ฌธ์ ๋ค์ ์ฌ์ผ๋ก ๋์ด๊ฐ๋ AudioComponent์ World๋ฅผ ์ฌ ๋ฑ๋กํด์ฃผ๋ ๋ก์ง์ ๊ตฌํํ๋ค.
void UPTAudioSubsystem::RegisterData() { int32 MaxCount = static_cast<int32>(ESoundType::Max); for (int32 i = 0; i < MaxCount; ++i) { ESoundType SoundType = static_cast<ESoundType>(i); UAudioComponent* AudioComponent = GetAudioComponent(SoundType); if (!AudioComponent) { AudioComponent = NewObject<UAudioComponent>(this); AudioComponents.Add(SoundType, AudioComponent); } if (SoundType == ESoundType::BGM) { AudioComponent->bAutoActivate = true; } AudioComponent->RegisterComponentWithWorld(GetWorld()); //AudioComponent->RegisterComponent(); } } void UPTAudioSubsystem::UnRegisterData() { int32 MaxCount = static_cast<int32>(ESoundType::Max); for (int32 i = 0; i < MaxCount; ++i) { ESoundType SoundType = static_cast<ESoundType>(i); UAudioComponent* AudioComponent = GetAudioComponent(SoundType); if (!AudioComponent) { continue; } AudioComponent->UnregisterComponent(); } }
-
-
๊ฐ ์ฌ์ด๋ ํ์ ์ ๋ฐ๋ผ AssetManager์์ ๋ฆฌ์์ค๋ฅผ ๋น๋๊ธฐ๋ก ๋ก๋ํด์ 2D, 3D ์ฌ์ด๋๋ฅผ ์ฌ์ํ ์ ์๋๋ก ๊ตฌํ
void UPTAudioSubsystem::PlaySound3D_ByPath(ESoundType Type, const FSoftObjectPath& BGMPath, FVector Location) { if (UAudioComponent* AudioComponent = GetAudioComponent(Type)) { UPTAssetManager& AssetManager = UPTAssetManager::Get(); AssetManager.AsynchronusLoadAsset(BGMPath, [&, AudioComponent](UObject* result) { if (USoundBase* Sound = Cast<USoundBase>(result)) { AudioComponent->SetSound(Sound); AudioComponent->SetWorldLocation(Location); AudioComponent->Play(); } }); } } void UPTAudioSubsystem::PlaySound2D_ByPath(ESoundType Type, const FSoftObjectPath& Path) { if (UAudioComponent* AudioComponent = GetAudioComponent(Type)) { UPTAssetManager& AssetManager = UPTAssetManager::Get(); AssetManager.AsynchronusLoadAsset(Path, [&, AudioComponent](UObject* result) { if (USoundBase* Sound = Cast<USoundBase>(result)) { AudioComponent->SetSound(Sound); AudioComponent->Play(); } }); } }