|
|
@ -5,6 +5,7 @@ using UnityEngine; |
|
|
using Core.Settings; |
|
|
using Core.Settings; |
|
|
using Core.Tools.Saves; |
|
|
using Core.Tools.Saves; |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections; |
|
|
|
|
|
|
|
|
namespace Core.Audio |
|
|
namespace Core.Audio |
|
|
{ |
|
|
{ |
|
|
@ -65,7 +66,7 @@ namespace Core.Audio |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal float PlayMusic(string name, bool isLoop = true) |
|
|
internal IEnumerator PlayMusic(string name) |
|
|
{ |
|
|
{ |
|
|
if (_musicSource == null) |
|
|
if (_musicSource == null) |
|
|
{ |
|
|
{ |
|
|
@ -74,23 +75,49 @@ namespace Core.Audio |
|
|
_musicSource.volume = CoreSettings.data.musicVolume * MusicVolume; |
|
|
_musicSource.volume = CoreSettings.data.musicVolume * MusicVolume; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (_musicSource.volume > 0f) |
|
|
|
|
|
{ |
|
|
|
|
|
yield return null; |
|
|
|
|
|
_musicSource.volume -= Time.deltaTime / 2f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_musicSource.volume = 0; |
|
|
|
|
|
|
|
|
if (_musicAndSounds.ContainsKey(name)) |
|
|
if (_musicAndSounds.ContainsKey(name)) |
|
|
{ |
|
|
{ |
|
|
_musicSource.clip = _musicAndSounds[name]; |
|
|
_musicSource.clip = _musicAndSounds[name]; |
|
|
_musicSource.loop = isLoop; |
|
|
_musicSource.loop = true; |
|
|
|
|
|
|
|
|
_musicSource.gameObject.SetActive(true); |
|
|
_musicSource.gameObject.SetActive(true); |
|
|
|
|
|
_musicSource.enabled = true; |
|
|
|
|
|
|
|
|
_musicSource.Play(); |
|
|
_musicSource.Play(); |
|
|
|
|
|
|
|
|
return _musicAndSounds[name].length; |
|
|
while (_musicSource.volume < MusicVolume) |
|
|
|
|
|
{ |
|
|
|
|
|
yield return null; |
|
|
|
|
|
_musicSource.volume += Time.deltaTime / 2f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_musicSource.volume = MusicVolume; |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
throw new ArgumentNullException($"music \"{name}\" not found"); |
|
|
throw new ArgumentNullException($"music \"{name}\" not found"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal void StopMusic() |
|
|
internal IEnumerator StopMusic() |
|
|
{ |
|
|
{ |
|
|
|
|
|
while (_musicSource.volume > 0f) |
|
|
|
|
|
{ |
|
|
|
|
|
yield return null; |
|
|
|
|
|
_musicSource.volume -= Time.deltaTime / 2f; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_musicSource.volume = 0; |
|
|
|
|
|
|
|
|
_musicSource.Stop(); |
|
|
_musicSource.Stop(); |
|
|
|
|
|
|
|
|
|
|
|
_musicSource.volume = MusicVolume; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal float PlaySound(string name, bool isLoop = false) |
|
|
internal float PlaySound(string name, bool isLoop = false) |
|
|
@ -112,6 +139,8 @@ namespace Core.Audio |
|
|
playSource.loop = isLoop; |
|
|
playSource.loop = isLoop; |
|
|
|
|
|
|
|
|
playSource.gameObject.SetActive(true); |
|
|
playSource.gameObject.SetActive(true); |
|
|
|
|
|
playSource.enabled = true; |
|
|
|
|
|
|
|
|
playSource.Play(); |
|
|
playSource.Play(); |
|
|
|
|
|
|
|
|
return _musicAndSounds[name].length; |
|
|
return _musicAndSounds[name].length; |
|
|
@ -149,6 +178,8 @@ namespace Core.Audio |
|
|
playSource.clip = _voicesDictionary[LocalizationManager.CurrentLanguage][name]; |
|
|
playSource.clip = _voicesDictionary[LocalizationManager.CurrentLanguage][name]; |
|
|
|
|
|
|
|
|
playSource.gameObject.SetActive(true); |
|
|
playSource.gameObject.SetActive(true); |
|
|
|
|
|
playSource.enabled = true; |
|
|
|
|
|
|
|
|
playSource.Play(); |
|
|
playSource.Play(); |
|
|
|
|
|
|
|
|
return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; |
|
|
return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; |
|
|
|