타이틀 씬 배경음 추가, 중복 효과음 처리
This commit is contained in:
parent
aa85f0f1e7
commit
a2741f4a4d
@ -1667,6 +1667,63 @@ Transform:
|
||||
m_CorrespondingSourceObject: {fileID: 1615391355952105053, guid: 3b97f989cfc1d96429c3e39a4cdab30f, type: 3}
|
||||
m_PrefabInstance: {fileID: 217591545}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1001 &225733419
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
serializedVersion: 2
|
||||
m_Modification:
|
||||
serializedVersion: 3
|
||||
m_TransformParent: {fileID: 0}
|
||||
m_Modifications:
|
||||
- target: {fileID: 67364633892410427, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_Name
|
||||
value: AudioManager
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalRotation.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalRotation.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalRotation.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.x
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 7212275451918744368, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
propertyPath: m_LocalEulerAnglesHint.z
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_RemovedGameObjects: []
|
||||
m_AddedGameObjects: []
|
||||
m_AddedComponents: []
|
||||
m_SourcePrefab: {fileID: 100100000, guid: 3fbb4ace392baa04da5f5cb3ad6e12e0, type: 3}
|
||||
--- !u!1 &254087150
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
@ -8699,6 +8756,7 @@ SceneRoots:
|
||||
m_Roots:
|
||||
- {fileID: 191889762}
|
||||
- {fileID: 1196361500}
|
||||
- {fileID: 225733419}
|
||||
- {fileID: 652021013}
|
||||
- {fileID: 1748037861}
|
||||
- {fileID: 1033584370}
|
||||
|
@ -9,26 +9,43 @@ namespace BlueWater.Audios
|
||||
public class AudioManager : Singleton<AudioManager>
|
||||
{
|
||||
[Title("오디오 데이터")]
|
||||
[SerializeField] private BgmDataSo bgmDataSo;
|
||||
[SerializeField] private SfxDataSo sfxDataSo;
|
||||
[SerializeField] private int sfxChannelCount = 16;
|
||||
[SerializeField]
|
||||
private BgmDataSo _bgmDataSo;
|
||||
|
||||
[SerializeField]
|
||||
private SfxDataSo _sfxDataSo;
|
||||
|
||||
[SerializeField]
|
||||
private int _sfxChannelCount = 32;
|
||||
|
||||
[Title("오디오 믹서")]
|
||||
[SerializeField] private AudioMixer audioMixer;
|
||||
[SerializeField] private AudioMixerGroup masterMixerGroup;
|
||||
[SerializeField] private AudioMixerGroup bgmMixerGroup;
|
||||
[SerializeField] private AudioMixerGroup sfxMixerGroup;
|
||||
[SerializeField]
|
||||
private AudioMixer _audioMixer;
|
||||
|
||||
private Dictionary<string, AudioClip> bgmDictionary;
|
||||
private Dictionary<string, AudioClip> sfxDictionary;
|
||||
[SerializeField]
|
||||
private AudioMixerGroup _masterMixerGroup;
|
||||
|
||||
private AudioSource bgmAudioSource;
|
||||
private Dictionary<AudioSource, float> sfxPitchDictionary;
|
||||
[SerializeField]
|
||||
private AudioMixerGroup _bgmMixerGroup;
|
||||
|
||||
[SerializeField]
|
||||
private AudioMixerGroup _sfxMixerGroup;
|
||||
|
||||
[Title("중복 사운드 처리")]
|
||||
[SerializeField, Range(0f, 1f)]
|
||||
private float _sfxMinInterval = 0.09f;
|
||||
|
||||
private Dictionary<string, AudioClip> _bgmDictionary;
|
||||
private Dictionary<string, AudioClip> _sfxDictionary;
|
||||
|
||||
private AudioSource _bgmAudioSource;
|
||||
private Dictionary<AudioSource, float> _sfxPitchDictionary;
|
||||
private Dictionary<string, float> _sfxPlayTimeDictionary;
|
||||
|
||||
protected override void OnAwake()
|
||||
{
|
||||
InitDictionary();
|
||||
InitComponent();
|
||||
InitializeDictionary();
|
||||
InitializeComponents();
|
||||
|
||||
SceneManager.sceneLoaded += OnSceneLoaded;
|
||||
}
|
||||
@ -44,43 +61,45 @@ namespace BlueWater.Audios
|
||||
StopSfxAll();
|
||||
}
|
||||
|
||||
private void InitDictionary()
|
||||
private void InitializeDictionary()
|
||||
{
|
||||
bgmDictionary = new Dictionary<string, AudioClip>(bgmDataSo.BgmDataList.Count);
|
||||
foreach (var element in bgmDataSo.BgmDataList)
|
||||
_bgmDictionary = new Dictionary<string, AudioClip>(_bgmDataSo.BgmDataList.Count);
|
||||
foreach (var element in _bgmDataSo.BgmDataList)
|
||||
{
|
||||
bgmDictionary.Add(element.BgmName, element.Clip);
|
||||
_bgmDictionary.Add(element.BgmName, element.Clip);
|
||||
}
|
||||
|
||||
sfxDictionary = new Dictionary<string, AudioClip>(sfxDataSo.SfxDataList.Count);
|
||||
foreach (var element in sfxDataSo.SfxDataList)
|
||||
_sfxDictionary = new Dictionary<string, AudioClip>(_sfxDataSo.SfxDataList.Count);
|
||||
foreach (var element in _sfxDataSo.SfxDataList)
|
||||
{
|
||||
sfxDictionary.Add(element.SfxName, element.Clip);
|
||||
}
|
||||
_sfxDictionary.Add(element.SfxName, element.Clip);
|
||||
}
|
||||
|
||||
private void InitComponent()
|
||||
{
|
||||
bgmAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
bgmAudioSource.outputAudioMixerGroup = bgmMixerGroup;
|
||||
bgmAudioSource.loop = true;
|
||||
_sfxPlayTimeDictionary = new Dictionary<string, float>(_sfxDataSo.SfxDataList.Count);
|
||||
}
|
||||
|
||||
sfxPitchDictionary = new Dictionary<AudioSource, float>(sfxChannelCount);
|
||||
for (var i = 0; i < sfxChannelCount; i++)
|
||||
private void InitializeComponents()
|
||||
{
|
||||
_bgmAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
_bgmAudioSource.outputAudioMixerGroup = _bgmMixerGroup;
|
||||
_bgmAudioSource.loop = true;
|
||||
|
||||
_sfxPitchDictionary = new Dictionary<AudioSource, float>(_sfxChannelCount);
|
||||
for (var i = 0; i < _sfxChannelCount; i++)
|
||||
{
|
||||
var sfxAudioSource = gameObject.AddComponent<AudioSource>();
|
||||
sfxAudioSource.outputAudioMixerGroup = sfxMixerGroup;
|
||||
sfxAudioSource.outputAudioMixerGroup = _sfxMixerGroup;
|
||||
sfxAudioSource.loop = false;
|
||||
sfxPitchDictionary[sfxAudioSource] = sfxAudioSource.pitch;
|
||||
_sfxPitchDictionary[sfxAudioSource] = sfxAudioSource.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayBgm(string bgmName)
|
||||
{
|
||||
if (bgmDictionary.TryGetValue(bgmName, out var value))
|
||||
if (_bgmDictionary.TryGetValue(bgmName, out var value))
|
||||
{
|
||||
bgmAudioSource.clip = value;
|
||||
bgmAudioSource.Play();
|
||||
_bgmAudioSource.clip = value;
|
||||
_bgmAudioSource.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -90,18 +109,27 @@ namespace BlueWater.Audios
|
||||
|
||||
public void StopBgm()
|
||||
{
|
||||
bgmAudioSource.Stop();
|
||||
_bgmAudioSource.Stop();
|
||||
}
|
||||
|
||||
public void PlaySfx(string sfxName, float? duration = null)
|
||||
{
|
||||
if (sfxDictionary.TryGetValue(sfxName, out var value))
|
||||
if (_sfxDictionary.TryGetValue(sfxName, out var value))
|
||||
{
|
||||
if (_sfxPlayTimeDictionary.TryGetValue(sfxName, out var lastPlayTime))
|
||||
{
|
||||
if (Time.time - lastPlayTime < _sfxMinInterval)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
var availableSfxAudioSource = GetAvailableSfxAudioSource();
|
||||
availableSfxAudioSource.clip = value;
|
||||
sfxPitchDictionary[availableSfxAudioSource] = duration.HasValue ? value.length / duration.Value : 1f;
|
||||
availableSfxAudioSource.pitch = sfxPitchDictionary[availableSfxAudioSource] * Time.timeScale;
|
||||
_sfxPitchDictionary[availableSfxAudioSource] = duration.HasValue ? value.length / duration.Value : 1f;
|
||||
availableSfxAudioSource.pitch = _sfxPitchDictionary[availableSfxAudioSource] * Time.timeScale;
|
||||
availableSfxAudioSource.Play();
|
||||
|
||||
_sfxPlayTimeDictionary[sfxName] = Time.time;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -111,9 +139,9 @@ namespace BlueWater.Audios
|
||||
|
||||
public void StopSfx(string sfxName)
|
||||
{
|
||||
if (sfxDictionary.TryGetValue(sfxName, out var clip))
|
||||
if (_sfxDictionary.TryGetValue(sfxName, out var clip))
|
||||
{
|
||||
foreach (var element in sfxPitchDictionary.Keys)
|
||||
foreach (var element in _sfxPitchDictionary.Keys)
|
||||
{
|
||||
if (element.clip == clip && element.isPlaying)
|
||||
{
|
||||
@ -129,7 +157,7 @@ namespace BlueWater.Audios
|
||||
|
||||
public void StopSfxAll()
|
||||
{
|
||||
foreach (var element in sfxPitchDictionary.Keys)
|
||||
foreach (var element in _sfxPitchDictionary.Keys)
|
||||
{
|
||||
if (element.isPlaying)
|
||||
{
|
||||
@ -140,7 +168,7 @@ namespace BlueWater.Audios
|
||||
|
||||
private AudioSource GetAvailableSfxAudioSource()
|
||||
{
|
||||
foreach (var element in sfxPitchDictionary.Keys)
|
||||
foreach (var element in _sfxPitchDictionary.Keys)
|
||||
{
|
||||
if (!element.isPlaying)
|
||||
{
|
||||
@ -151,29 +179,29 @@ namespace BlueWater.Audios
|
||||
// 모든 AudioSource가 사용 중이면 첫 번째 AudioSource를 재사용
|
||||
//return sfxPitchDictionary.Keys.GetEnumerator().Current;
|
||||
|
||||
using var enumerator = sfxPitchDictionary.Keys.GetEnumerator();
|
||||
using var enumerator = _sfxPitchDictionary.Keys.GetEnumerator();
|
||||
enumerator.MoveNext();
|
||||
return enumerator.Current;
|
||||
}
|
||||
|
||||
public void SetMasterVolume(float volume)
|
||||
{
|
||||
audioMixer.SetFloat("Master", volume);
|
||||
_audioMixer.SetFloat("Master", volume);
|
||||
}
|
||||
|
||||
public void SetBgmVolume(float volume)
|
||||
{
|
||||
audioMixer.SetFloat("Bgm", volume);
|
||||
_audioMixer.SetFloat("Bgm", volume);
|
||||
}
|
||||
|
||||
public void SetSfxVolume(float volume)
|
||||
{
|
||||
audioMixer.SetFloat("Sfx", volume);
|
||||
_audioMixer.SetFloat("Sfx", volume);
|
||||
}
|
||||
|
||||
public void SetPitchSfxAll(float pitch)
|
||||
{
|
||||
foreach (var element in sfxPitchDictionary)
|
||||
foreach (var element in _sfxPitchDictionary)
|
||||
{
|
||||
element.Key.pitch = element.Value * pitch;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using BlueWater.Audios;
|
||||
using Sirenix.OdinInspector;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
@ -19,6 +20,9 @@ namespace BlueWater.Titles
|
||||
[SerializeField]
|
||||
private TMP_Text _versionText;
|
||||
|
||||
[SerializeField]
|
||||
private string _dailyBgm = "DailyBgm1";
|
||||
|
||||
private bool _isQuitting;
|
||||
|
||||
private void Awake()
|
||||
@ -28,6 +32,7 @@ namespace BlueWater.Titles
|
||||
|
||||
private void Start()
|
||||
{
|
||||
AudioManager.Instance.PlayBgm(_dailyBgm);
|
||||
_startGameButton.onClick.AddListener(SceneController.Instance.FadeIn);
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,11 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_persistent: 1
|
||||
bgmDataSo: {fileID: 11400000, guid: f5c890c4ba0370e4e9226493ad883bb7, type: 2}
|
||||
sfxDataSo: {fileID: 11400000, guid: 9adcc081767771e4098f523ee1fffa07, type: 2}
|
||||
sfxChannelCount: 32
|
||||
audioMixer: {fileID: 24100000, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
masterMixerGroup: {fileID: 24300002, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
bgmMixerGroup: {fileID: 2675715275340035989, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
sfxMixerGroup: {fileID: -2540351765735581840, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
_bgmDataSo: {fileID: 11400000, guid: f5c890c4ba0370e4e9226493ad883bb7, type: 2}
|
||||
_sfxDataSo: {fileID: 11400000, guid: 9adcc081767771e4098f523ee1fffa07, type: 2}
|
||||
_sfxChannelCount: 32
|
||||
_audioMixer: {fileID: 24100000, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
_masterMixerGroup: {fileID: 24300002, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
_bgmMixerGroup: {fileID: 2675715275340035989, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
_sfxMixerGroup: {fileID: -2540351765735581840, guid: ae14a59e484da75438db3648143481f0, type: 2}
|
||||
_sfxMinInterval: 0.09
|
||||
|
Loading…
Reference in New Issue
Block a user