diff --git a/Assets/Prototype/Core/Core.dll b/Assets/Prototype/Core/Core.dll index 9cd189f..5917e14 100644 Binary files a/Assets/Prototype/Core/Core.dll and b/Assets/Prototype/Core/Core.dll differ diff --git a/Assets/Prototype/Core/CoreEditor.dll b/Assets/Prototype/Core/CoreEditor.dll index 537badc..10af518 100644 Binary files a/Assets/Prototype/Core/CoreEditor.dll and b/Assets/Prototype/Core/CoreEditor.dll differ diff --git a/Assets_DLL/Core/Audio/AudioController.cs b/Assets_DLL/Core/Audio/AudioController.cs index 5b0aab3..75836ce 100644 --- a/Assets_DLL/Core/Audio/AudioController.cs +++ b/Assets_DLL/Core/Audio/AudioController.cs @@ -7,21 +7,24 @@ using Core.Tools.Saves; namespace Core.Audio { - public static class AudioController + public class AudioController : MonoBehaviour { private static AudioController2D _audio2D = null; + private static AudioController3D _audio3D = null; internal static void Init() { GameObject audioParent = new GameObject("[AudioController]"); + audioParent.AddComponent(); + GameObject.DontDestroyOnLoad(audioParent); Dictionary musicAnsSoundsDictionary = new Dictionary(); Dictionary> languageVoicesDictionary = new Dictionary>(); - AudioClip[] music = Resources.LoadAll("CoreAudio/Musics"); - AudioClip[] sounds = Resources.LoadAll("CoreAudio/Sounds"); + AudioClip[] music = Resources.LoadAll("Audio/Musics"); + AudioClip[] sounds = Resources.LoadAll("Audio/Sounds"); for (int i = 0; i < music.Length; i++) musicAnsSoundsDictionary.Add(music[i].name, music[i]); @@ -45,6 +48,9 @@ namespace Core.Audio _audio2D = new AudioController2D(); _audio2D.Init(audioParent.transform, musicAnsSoundsDictionary, languageVoicesDictionary); + + _audio3D = new AudioController3D(); + _audio3D.Init(audioParent.transform, musicAnsSoundsDictionary, languageVoicesDictionary); } public static float MusicVolume @@ -86,13 +92,40 @@ namespace Core.Audio public static float PlaySound(string name, bool isLoop = false) => _audio2D.PlaySound(name, isLoop); - public static void StopSound(string name) => + public static void StopSound(string name) + { _audio2D.StopSound(name); + _audio3D.StopSound(name); + } public static float PlayVoice(string name) => _audio2D.PlayVoice(name); - public static void StopVoice(string name) => + public static void StopVoice(string name) + { _audio2D.StopVoice(name); + _audio3D.StopVoice(name); + } + + public static float PlaySound(string name, Transform target, float minDistance, float maxDistance, bool isLoop = false) => + _audio3D.PlaySound(name, target, minDistance, maxDistance, isLoop); + + public static float PlayVoice(string name, Transform target, float minDistance, float maxDistance) => + _audio3D.PlayVoice(name, target, minDistance, maxDistance); + + private Transform _currentTarget = null; + + private void Update() + { + if (_currentTarget == null) + { + AudioListener listener = FindObjectOfType(); + + if (listener == null) + _currentTarget = listener.transform; + } + else + transform.position = _currentTarget.position; + } } } \ No newline at end of file diff --git a/Assets_DLL/Core/Audio/AudioController2D.cs b/Assets_DLL/Core/Audio/AudioController2D.cs index 6af05c2..294eb66 100644 --- a/Assets_DLL/Core/Audio/AudioController2D.cs +++ b/Assets_DLL/Core/Audio/AudioController2D.cs @@ -4,6 +4,7 @@ using System.Linq; using UnityEngine; using Core.Settings; using Core.Tools.Saves; +using System; namespace Core.Audio { @@ -82,10 +83,7 @@ namespace Core.Audio return _musicAndSounds[name].length; } else - { - Debug.LogError($"AudioController: music \"{name}\" not found"); - return 0f; - } + throw new ArgumentNullException($"music \"{name}\" not found"); } internal void StopMusic() @@ -100,7 +98,6 @@ namespace Core.Audio if (playSource == null) { playSource = _soundsParent.AddComponent(); - playSource.loop = false; playSource.playOnAwake = false; playSource.volume = CoreSettings.data.soundsVolume * SoundsVolume; @@ -116,10 +113,7 @@ namespace Core.Audio return _musicAndSounds[name].length; } else - { - Debug.LogError($"AudioController: sound \"{name}\" not found"); - return 0f; - } + throw new ArgumentNullException($"sound \"{name}\" not found"); } internal void StopSound(string name) @@ -154,16 +148,10 @@ namespace Core.Audio return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; } else - { - Debug.LogError($"AudioController: voice \"{name}\" not found"); - return 0f; - } + throw new ArgumentNullException($"voice \"{name}\" not found"); } else - { - Debug.LogError($"AudioController: voice \"{name}\" not found"); - return 0f; - } + throw new ArgumentNullException($"Avoice \"{name}\" not found"); } internal void StopVoice(string name) diff --git a/Assets_DLL/Core/Audio/AudioController3D.cs b/Assets_DLL/Core/Audio/AudioController3D.cs new file mode 100644 index 0000000..33e5c27 --- /dev/null +++ b/Assets_DLL/Core/Audio/AudioController3D.cs @@ -0,0 +1,134 @@ +using Core.Localization; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Core.Settings; +using Core.Tools.Saves; +using System; + +namespace Core.Audio +{ + internal class AudioController3D + { + internal void Init(Transform parent, Dictionary musicAnsSounds, Dictionary> voicesDictionary) + { + _musicAndSounds = musicAnsSounds; + _voicesDictionary = voicesDictionary; + } + + private GameObject _musicParent = null; + private GameObject _soundsParent = null; + private GameObject _voicesParent = null; + + private List _soundsSources = new List(); + private List _voicesSources = new List(); + + private Dictionary _musicAndSounds = new Dictionary(); + private Dictionary> _voicesDictionary = new Dictionary>(); + + internal float SoundsVolume + { + get => SaveManager.GetFloat("MusicVolume", 1f); + set + { + for (int i = 0; i < _soundsSources.Count; i++) + { + if (_soundsSources[i] != null) + _soundsSources[i].volume = CoreSettings.data.soundsVolume * value; + } + } + } + + internal float VoicesVolume + { + get => PlayerPrefs.GetFloat("MusicVolume", 1f); + set + { + for (int i = 0; i < _voicesSources.Count; i++) + { + if (_voicesSources[i] != null) + _voicesSources[i].volume = CoreSettings.data.voicesVolume * value; + } + } + } + + internal float PlaySound(string name, Transform target, float minDistance, float maxDistance, bool isLoop = false) + { + AudioSource playSource = _soundsSources.Where(s => s != null && !s.isPlaying).FirstOrDefault(); + + if (playSource == null) + { + playSource = _soundsParent.AddComponent(); + playSource.playOnAwake = false; + playSource.volume = CoreSettings.data.soundsVolume * SoundsVolume; + + _soundsSources.Add(playSource); + } + + if (_musicAndSounds.ContainsKey(name)) + { + playSource.clip = _musicAndSounds[name]; + playSource.loop = isLoop; + playSource.minDistance = minDistance; + playSource.maxDistance = maxDistance; + playSource.transform.SetParent(target); + playSource.transform.localPosition = Vector3.zero; + playSource.Play(); + + return _musicAndSounds[name].length; + } + else + throw new ArgumentNullException($"sound \"{name}\" not found"); + } + + internal void StopSound(string name) + { + AudioSource playSource = _soundsSources.Where(s => s != null && s.clip.name == name).FirstOrDefault(); + + if (playSource != null) + playSource.Stop(); + } + + internal float PlayVoice(string name, Transform target, float minDistance, float maxDistance) + { + AudioSource playSource = _voicesSources.Where(s => s != null && !s.isPlaying).FirstOrDefault(); + + if (playSource == null) + { + playSource = _voicesParent.AddComponent(); + playSource.loop = false; + playSource.playOnAwake = false; + playSource.volume = CoreSettings.data.voicesVolume * VoicesVolume; + + _voicesSources.Add(playSource); + } + + if (_voicesDictionary.ContainsKey(LocalizationManager.CurrentLanguage)) + { + if (_voicesDictionary[LocalizationManager.CurrentLanguage].ContainsKey(name)) + { + playSource.clip = _voicesDictionary[LocalizationManager.CurrentLanguage][name]; + playSource.minDistance = minDistance; + playSource.maxDistance = maxDistance; + playSource.transform.SetParent(target); + playSource.transform.localPosition = Vector3.zero; + playSource.Play(); + + return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; + } + else + throw new ArgumentNullException($"voice \"{name}\" not found"); + } + else + throw new ArgumentNullException($"voice \"{name}\" not found"); + } + + internal void StopVoice(string name) + { + AudioSource playSource = _voicesSources.Where(s => s != null && s.clip.name == name).FirstOrDefault(); + + if (playSource != null) + playSource.Stop(); + } + } +} diff --git a/Assets_DLL/Core/IAP/PurchaseButton.cs b/Assets_DLL/Core/IAP/PurchaseButton.cs index 7e477fe..b40d135 100644 --- a/Assets_DLL/Core/IAP/PurchaseButton.cs +++ b/Assets_DLL/Core/IAP/PurchaseButton.cs @@ -11,6 +11,7 @@ namespace Core.Ads public sealed class PurchaseButton : MonoBehaviour { [SerializeField] private string _productId = ""; + [SerializeField] private Text _priceText = null; [SerializeField] private UnityEvent _onSucces = null; [SerializeField] private UnityEvent _onFailed = null; @@ -26,6 +27,9 @@ namespace Core.Ads private void OnEnable() { + if (_priceText != null) + _priceText.text = PurchaseManager.GetLocalizedPrice(_productId); + PurchaseManager.OnPurchaseSuccess += CheckAdsEnablingAfterPurchasing; PurchaseManager.OnPurchaseFailed += PurchaseManager_OnPurchaseFailed; @@ -41,10 +45,12 @@ namespace Core.Ads private void CheckAdsEnablingAfterPurchasing(string productId) { - if (_productId == productId && !CoreSettings.data.IsProductConsumable(productId)) + if (_productId == productId) { _onSucces?.Invoke(); - gameObject.SetActive(false); + + if (!CoreSettings.data.IsProductConsumable(productId)) + gameObject.SetActive(false); } } diff --git a/Assets_DLL/Core/Tools/BufferManager.cs b/Assets_DLL/Core/Tools/BufferManager.cs new file mode 100644 index 0000000..5b8af16 --- /dev/null +++ b/Assets_DLL/Core/Tools/BufferManager.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; + +namespace Core.Tools +{ + public static class BufferManager + { + private static Dictionary _buffer = new Dictionary(); + + public static void Add(string key, T element) + { + if (_buffer.ContainsKey(key)) + _buffer[key] = element; + else + _buffer.Add(key, element); + } + + public static T Get(string key) + { + if (_buffer.ContainsKey(key)) + return (T)_buffer[key]; + + return default(T); + } + + public static void Remove(string key) + { + if (_buffer.ContainsKey(key)) + _buffer.Remove(key); + } + } +} diff --git a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache index f5e894a..eb069b6 100644 Binary files a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache and b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache differ diff --git a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache index 4d57bc0..4c56002 100644 --- a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache +++ b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -049145f5314f464185eb4974b4434a906bbba395 +7fd1797d3498be18a922a7bf796a7fa6c67322c0 diff --git a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll index 9cd189f..5917e14 100644 Binary files a/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll and b/Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll differ diff --git a/Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs b/Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs index 110fcd2..0de7042 100644 --- a/Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs +++ b/Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs @@ -2,6 +2,7 @@ using Core.Settings; using System.Collections.Generic; using UnityEditor; +using UnityEngine.UI; namespace CoreEditor.Localization { @@ -15,6 +16,7 @@ namespace CoreEditor.Localization EditorGUILayout.Space(5); SerializedProperty productId = serializedObject.FindProperty("_productId"); + SerializedProperty priceText = serializedObject.FindProperty("_priceText"); List products = new List(); @@ -42,6 +44,10 @@ namespace CoreEditor.Localization currentIndex = EditorGUILayout.Popup("Product ID:", currentIndex, products.ToArray()); + EditorGUILayout.Space(3); + + priceText.objectReferenceValue = (Text)EditorGUILayout.ObjectField("Price text:", (Text)priceText.objectReferenceValue, typeof(Text), true); + productId.stringValue = products[currentIndex]; EditorGUILayout.Space(10); diff --git a/Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs b/Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs index dd3eed9..fcb4886 100644 --- a/Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs +++ b/Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs @@ -18,7 +18,7 @@ namespace CoreEditor.Localization EditorGUILayout.BeginHorizontal("BOX"); GUILayout.Label("ID", EditorStyles.label); - GUILayout.Label(" Prefab", EditorStyles.label); + GUILayout.Label("Prefab", EditorStyles.label); GUILayout.Label("StartCount", EditorStyles.label, GUILayout.MaxWidth(64)); GUILayout.Label("", EditorStyles.label, GUILayout.MaxWidth(64)); @@ -39,6 +39,8 @@ namespace CoreEditor.Localization id.stringValue = EditorGUILayout.TextField(id.stringValue); + prefab.objectReferenceValue = (ParticleSystem)EditorGUILayout.ObjectField((ParticleSystem)prefab.objectReferenceValue, typeof(ParticleSystem), true); + EditorGUILayout.PropertyField(prefab, GUIContent.none); count.intValue = EditorGUILayout.IntField(count.intValue, GUILayout.MaxWidth(64)); diff --git a/Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs b/Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs index d2f689f..0f9c246 100644 --- a/Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs +++ b/Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs @@ -99,13 +99,13 @@ namespace Core.Tools newRect.x += rect.width - 305; newRect.width = 200; - GUI.Label(newRect, $"Used assets count: {usedCount}"); + GUI.Label(newRect, $"Used: {usedCount}"); newRect = rect; newRect.x += rect.width - 155; newRect.width = 200; - GUI.Label(newRect, $"Unused assets count: {unusedCount}"); + GUI.Label(newRect, $"Unused: {unusedCount}"); } GUI.backgroundColor = Color.white; diff --git a/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache b/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache index 896379c..dcfe91f 100644 Binary files a/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache and b/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache differ diff --git a/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll b/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll index 537badc..10af518 100644 Binary files a/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll and b/Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll differ diff --git a/Builds/Core_1.8.3.unitypackage b/Builds/Core_1.8.3.unitypackage new file mode 100644 index 0000000..53cf7b1 Binary files /dev/null and b/Builds/Core_1.8.3.unitypackage differ