diff --git a/Assets_DLL/Core/Ads/AdsManager.cs b/Assets_DLL/Core/Ads/AdsManager.cs index 8e6b077..f37ffed 100644 --- a/Assets_DLL/Core/Ads/AdsManager.cs +++ b/Assets_DLL/Core/Ads/AdsManager.cs @@ -161,9 +161,6 @@ namespace Core.Ads public static bool IsRewardedReady() { - if (IsAdsDisabled()) - return false; - if (_rewarded == null) { Debug.LogError("Ads bridge object does not implement IRewardedBridge"); @@ -183,9 +180,6 @@ namespace Core.Ads { Debug.Log("Called show rewarded"); - if (IsAdsDisabled()) - return; - if (_rewarded == null) { Debug.LogError("Ads bridge object does not implement IRewardedBridge"); diff --git a/Assets_DLL/Core/Audio/AudioController.cs b/Assets_DLL/Core/Audio/AudioController.cs deleted file mode 100644 index 55c9962..0000000 --- a/Assets_DLL/Core/Audio/AudioController.cs +++ /dev/null @@ -1,336 +0,0 @@ -using Core.Localization; -using Core.Settings; -using Core.Tools.Saves; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; - -namespace Core.Audio -{ - public static class AudioController - { - private static List _audioPlayers = new List(); - - private static Dictionary _nonLocalizedSoundsDictionary = new Dictionary(); - private static Dictionary> _localizedSoundDictionary = new Dictionary>(); - - private static GameObject _parent = null; - - internal static void Init() - { - _parent = new GameObject("[AudioController]"); - - GameObject.DontDestroyOnLoad(_parent); - - AudioClip[] nonLocalizedSounds = Resources.LoadAll("Audio/NonLocalizedSounds"); - - for (int i = 0; i < nonLocalizedSounds.Length; i++) - _nonLocalizedSoundsDictionary.Add(nonLocalizedSounds[i].name, nonLocalizedSounds[i]); - - for (int l = 0; l < CoreSettings.data.availableLanguages.Count; l++) - { - SystemLanguage language = CoreSettings.data.availableLanguages[l]; - - Dictionary voicesDictionary = new Dictionary(); - - AudioClip[] voices = Resources.LoadAll("CoreAudio/LocalizedSounds/" + language.ToString()); - - for (int i = 0; i < voices.Length; i++) - voicesDictionary.Add(voices[i].name, voices[i]); - - _localizedSoundDictionary.Add(language, voicesDictionary); - } - } - - public static AudioPlayer CreatePlayer(string clipName) => - CreatePlayer(FindAudioClip(clipName)); - - #region AudioPlayer manager - - public static AudioPlayer CreatePlayer(AudioClip clip) - { - if (clip == null) - return null; - - AudioPlayer player = _audioPlayers.Where(p => p.AudioClip == null).FirstOrDefault(); - - if (player == null) - { - GameObject newPlayer = new GameObject("AudioPlayer"); - newPlayer.transform.SetParent(_parent.transform); - - newPlayer.AddComponent(); - player = newPlayer.AddComponent(); - - player.OnNeedDestroy += DestroyPlayer; - - _audioPlayers.Add(player); - } - - player.Init(clip); - - return player; - } - - private static void DestroyPlayer(AudioPlayer player) - { - _audioPlayers.Remove(player); - - GameObject gameObject = player.gameObject; - - GameObject.Destroy(player); - - player = gameObject.AddComponent(); - - player.OnNeedDestroy += DestroyPlayer; - - _audioPlayers.Add(player); - } - - #endregion - - #region Volume - - public static void SetVolume(AudioGroup group, float volume) - { - SaveManager.SetFloat(group.ToString() + "_volume", volume); - - for (int i = 0; i < _audioPlayers.Count; i++) - { - if (_audioPlayers[i].AudioClip != null && _audioPlayers[i].AudioGroup == group) - _audioPlayers[i].UpdateVolume(); - } - } - - public static float GetVolume(AudioGroup group) => - SaveManager.GetFloat(group.ToString() + "_volume", 1f); - - #endregion - - #region Find player with parametres - - public static AudioPlayer FindPlayer(string clipName) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayer(clip, -1, -1); - } - - public static AudioPlayer FindPlayer(string clipName, AudioGroup group) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayer(clip, (int)group, -1); - } - - public static AudioPlayer FindPlayer(string clipName, SourceType type) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayer(clip, -1, (int)type); - } - - public static AudioPlayer FindPlayer(string clipName, AudioGroup group, SourceType type) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayer(clip, (int)group, (int)type); - } - - public static AudioPlayer FindPlayer(AudioClip clip) => - FindPlayer(clip, -1, -1); - public static AudioPlayer FindPlayer(AudioClip clip, AudioGroup group) => - FindPlayer(clip, (int)group, -1); - - public static AudioPlayer FindPlayer(AudioClip clip, SourceType type) => - FindPlayer(clip, -1, (int)type); - - public static AudioPlayer FindPlayer(AudioClip clip, AudioGroup group, SourceType type) => - FindPlayer(clip, (int)group, (int)type); - - public static AudioPlayer FindPlayer(AudioGroup group) => - FindPlayer(null, (int)group, -1); - - public static AudioPlayer FindPlayer(SourceType type) => - FindPlayer(null, -1, (int)type); - - public static AudioPlayer FindPlayer(AudioGroup group, SourceType type) => - FindPlayer(null, (int)group, (int)type); - - private static AudioPlayer FindPlayer(AudioClip clip, int group = -1, int type = -1) - { - AudioPlayer[] players = FindPlayers(clip, group, type); - - if (players != null && players.Length > 0) - return players[0]; - else - return null; - } - - #endregion - - #region Find players with parametres - - public static AudioPlayer[] FindPlayers(string clipName) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayers(clip, -1, -1); - } - - public static AudioPlayer[] FindPlayers(string clipName, AudioGroup group) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayers(clip, (int)group, -1); - } - - public static AudioPlayer[] FindPlayers(string clipName, SourceType type) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayers(clip, -1, (int)type); - } - - public static AudioPlayer[] FindPlayers(string clipName, AudioGroup group, SourceType type) - { - AudioClip clip = FindAudioClip(clipName); - - if (clip == null) - return null; - - return FindPlayers(clip, (int)group, (int)type); - } - - public static AudioPlayer[] FindPlayers(AudioClip clip) => - FindPlayers(clip, -1, -1); - public static AudioPlayer[] FindPlayers(AudioClip clip, AudioGroup group) => - FindPlayers(clip, (int)group, -1); - - public static AudioPlayer[] FindPlayers(AudioClip clip, SourceType type) => - FindPlayers(clip, -1, (int)type); - - public static AudioPlayer[] FindPlayers(AudioClip clip, AudioGroup group, SourceType type) => - FindPlayers(clip, (int)group, (int)type); - - public static AudioPlayer[] FindPlayers(AudioGroup group) => - FindPlayers(null, (int)group, -1); - - public static AudioPlayer[] FindPlayers(SourceType type) => - FindPlayers(null, -1, (int)type); - - public static AudioPlayer[] FindPlayers(AudioGroup group, SourceType type) => - FindPlayers(null, (int)group, (int)type); - - private static AudioPlayer[] FindPlayers(AudioClip clip, int group = -1, int type = -1) - { - AudioPlayer[] audioPlayers = new AudioPlayer[0]; - - if (clip != null && group != -1 && type != -1) - { - AudioGroup audioGroup = (AudioGroup)group; - SourceType sourceType = (SourceType)type; - - audioPlayers = _audioPlayers.Where(p => p.AudioClip == clip && p.AudioGroup == audioGroup && p.SourceType == sourceType).ToArray(); - - return audioPlayers; - } - - if (clip != null && group != -1 && type == -1) - { - AudioGroup audioGroup = (AudioGroup)group; - - audioPlayers = _audioPlayers.Where(p => p.AudioClip == clip && p.AudioGroup == audioGroup).ToArray(); - - return audioPlayers; - } - - - if (clip != null && group == -1 && type != -1) - { - SourceType sourceType = (SourceType)type; - - audioPlayers = _audioPlayers.Where(p => p.AudioClip == clip && p.SourceType == sourceType).ToArray(); - - return audioPlayers; - } - - if (clip != null && group == -1 && type == -1) - { - SourceType sourceType = (SourceType)type; - - audioPlayers = _audioPlayers.Where(p => p.AudioClip == clip).ToArray(); - - return audioPlayers; - } - - if (clip == null && group != -1 && type != -1) - { - AudioGroup audioGroup = (AudioGroup)group; - SourceType sourceType = (SourceType)type; - - audioPlayers = _audioPlayers.Where(p => p.AudioGroup == audioGroup && p.SourceType == sourceType).ToArray(); - - return audioPlayers; - } - - if (clip == null && group != -1 && type == -1) - { - AudioGroup audioGroup = (AudioGroup)group; - - audioPlayers = _audioPlayers.Where(p => p.AudioGroup == audioGroup).ToArray(); - - return audioPlayers; - } - - if (clip == null && group == -1 && type != -1) - { - SourceType sourceType = (SourceType)type; - - audioPlayers = _audioPlayers.Where(p => p.SourceType == sourceType).ToArray(); - - return audioPlayers; - } - - return audioPlayers; - } - - #endregion - - public static AudioClip FindAudioClip(string clipName) - { - SystemLanguage language = LocalizationManager.CurrentLanguage; - - AudioClip clip = _localizedSoundDictionary[language].Where(d => d.Key == clipName).FirstOrDefault().Value; - - if (clip == null) - clip = _nonLocalizedSoundsDictionary.Where(d => d.Key == clipName).FirstOrDefault().Value; - - if (clip == null) - Debug.LogError($"AudioController: clip \"{clipName}\" not found"); - - return clip; - } - } -} \ No newline at end of file diff --git a/Assets_DLL/Core/Audio/AudioPlayer.cs b/Assets_DLL/Core/Audio/AudioPlayer.cs index 746574d..07f5902 100644 --- a/Assets_DLL/Core/Audio/AudioPlayer.cs +++ b/Assets_DLL/Core/Audio/AudioPlayer.cs @@ -1,190 +1,77 @@ -using Core.Settings; -using System; -using System.Collections; -using UnityEngine; +using UnityEngine; +using UnityEngine.UI; namespace Core.Audio { - public enum SourceType - { - Type2D = 0, - Type3D = 1, - } - - public enum AudioGroup - { - Music = 0, - Sound = 1, - Voice = 2, - } - [RequireComponent(typeof(AudioSource))] - public sealed class AudioPlayer : MonoBehaviour + public class AudioPlayer : MonoBehaviour { - internal event Action OnNeedDestroy = null; - - private event Action _onComplete = null; - private AudioSource _audioSource = null; - private SourceType _sourceType = SourceType.Type2D; - private AudioGroup _group = AudioGroup.Sound; - private float _customVolume = 1f; - private bool _isLoop = false; - private Transform _target = null; - - private Coroutine _playCoroutine = null; - - public AudioClip AudioClip => (_audioSource != null) ? _audioSource.clip : null; - public SourceType SourceType => _sourceType; - public AudioGroup AudioGroup => _group; - public float CustomVolume => _customVolume; - public bool IsPlaying => _audioSource != null && _audioSource.clip != null && _audioSource.isPlaying; - public bool IsLoop => _isLoop; - public Transform Target => _target; - - internal void Init(AudioClip clip) - { - _audioSource = GetComponent(); + [SerializeField] private AudioClip[] _clips = new AudioClip[0]; - _onComplete = null; + [Space] - _audioSource.playOnAwake = false; - _audioSource.Stop(); - - SetGroup(AudioGroup.Sound); - SetLoop(false); - SetCustomVolume(1f); - SetSource(SourceType.Type2D); - SetTarget(null); - SetMinDistance(0f); - SetMaxDistance(0f); - - UpdateVolume(); - - _audioSource.clip = clip; - } - - internal void UpdateVolume() => - _audioSource.volume = _customVolume * AudioController.GetVolume(_group) * CoreSettings.data.volume[(int)_group]; - - public void Stop() - { - _audioSource.Stop(); - _audioSource.clip = null; + [SerializeField] private float _delayForPlay = 0f; - if (_playCoroutine != null) - StopCoroutine(_playCoroutine); - - OnNeedDestroy?.Invoke(this); - } - - private void Update() - { - if (_sourceType == SourceType.Type3D && _target != null) - transform.position = _target.position; - else - transform.localPosition = Vector3.zero; - } - - public AudioPlayer SetSource(SourceType type) - { - _sourceType = type; - - if (_sourceType == SourceType.Type2D) - { - _audioSource.spatialBlend = 0f; - _audioSource.rolloffMode = AudioRolloffMode.Linear; - } - else - { - _audioSource.spatialBlend = 1f; - _audioSource.rolloffMode = AudioRolloffMode.Custom; - _audioSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0f, 1f, 1f, 0f)); - } + [Header("Flags")] - return this; - } + [SerializeField] private bool _playOnEnable = false; + [SerializeField] private bool _playOnClick = false; + [SerializeField] private bool _playWithParticle = false; - public AudioPlayer SetTarget(Transform target) - { - _target = target; - return this; - } + private AudioSource _source = null; + private ParticleSystem _particle = null; + private Button _button = null; - public AudioPlayer SetMinDistance(float minDistance) - { - _audioSource.minDistance = minDistance; - return this; - } - - public AudioPlayer SetMaxDistance(float maxDistance) - { - _audioSource.maxDistance = maxDistance; - return this; - } + private bool _lastParticleState = false; - public AudioPlayer SetCustomVolume(float volume) + private void Awake() { - _customVolume = volume; + _source = GetComponent(); + _particle = GetComponent(); + _button = GetComponent