From 9df6e56a9512566ee6c236556ad1593ff8570e98 Mon Sep 17 00:00:00 2001 From: Seraph Date: Sun, 5 Jun 2022 14:19:36 +0300 Subject: [PATCH] =?UTF-8?q?-=20=D0=A4=D1=96=D0=BA=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets_DLL/Core/Ads/AdsManager.cs | 3 + Assets_DLL/Core/Audio/AudioController.cs | 6 +- Assets_DLL/Core/Audio/AudioController2D.cs | 4 +- Assets_DLL/Core/Audio/AudioController3D.cs | 22 ++- Assets_DLL/Core/Audio/PlayAudioFile.cs | 139 ++++++++++++++++++ Assets_DLL/Core/CoreInitializer.cs | 2 +- .../CameraVerticalStretchingAdapter.cs | 2 +- .../AspectAdapters/CanvasAspectAdapter.cs | 2 +- .../Tools/Pool/Particles/ParticlesPool.cs | 4 +- Assets_DLL/Core/Tools/Saves/SaveData.cs | 8 - Assets_DLL/Core/Tools/Saves/SaveManager.cs | 11 +- .../Core.csproj.AssemblyReference.cache | Bin 126743 -> 11 bytes .../Core.csproj.CoreCompileInputs.cache | 2 +- .../Core/obj/Debug/netstandard2.0/Core.dll | Bin 53248 -> 56320 bytes .../Pool/Particles/ParticlesPoolEditor.cs | 18 +-- .../CoreEditor/Tools/UnusedAssetsMarker.cs | 4 +- .../obj/CoreEditor.csproj.nuget.dgspec.json | 61 -------- .../CoreEditor.csproj.AssemblyReference.cache | Bin 4401 -> 11 bytes .../obj/Debug/netstandard2.0/CoreEditor.dll | Bin 27136 -> 27136 bytes Assets_DLL/CoreEditor/obj/project.assets.json | 22 +-- Assets_DLL/CoreEditor/obj/project.nuget.cache | 2 +- 21 files changed, 193 insertions(+), 119 deletions(-) create mode 100644 Assets_DLL/Core/Audio/PlayAudioFile.cs diff --git a/Assets_DLL/Core/Ads/AdsManager.cs b/Assets_DLL/Core/Ads/AdsManager.cs index 0c22465..d70ca9c 100644 --- a/Assets_DLL/Core/Ads/AdsManager.cs +++ b/Assets_DLL/Core/Ads/AdsManager.cs @@ -17,6 +17,9 @@ namespace Core.Ads internal static void Init() { + if (!CoreSettings.data.needInterstitial && !CoreSettings.data.needBanner && !CoreSettings.data.needRewarded) + return; + GameObject holder = new GameObject("[AdsManager]"); GameObject bridge = null; diff --git a/Assets_DLL/Core/Audio/AudioController.cs b/Assets_DLL/Core/Audio/AudioController.cs index 75836ce..2cf6421 100644 --- a/Assets_DLL/Core/Audio/AudioController.cs +++ b/Assets_DLL/Core/Audio/AudioController.cs @@ -83,8 +83,8 @@ namespace Core.Audio } } - public static float PlayMusic(string name) => - _audio2D.PlayMusic(name); + public static float PlayMusic(string name, bool isLoop = false) => + _audio2D.PlayMusic(name, isLoop); public static void StopMusic() => _audio2D.StopMusic(); @@ -121,7 +121,7 @@ namespace Core.Audio { AudioListener listener = FindObjectOfType(); - if (listener == null) + if (listener != null) _currentTarget = listener.transform; } else diff --git a/Assets_DLL/Core/Audio/AudioController2D.cs b/Assets_DLL/Core/Audio/AudioController2D.cs index 294eb66..c9b3deb 100644 --- a/Assets_DLL/Core/Audio/AudioController2D.cs +++ b/Assets_DLL/Core/Audio/AudioController2D.cs @@ -65,12 +65,11 @@ namespace Core.Audio } } - internal float PlayMusic(string name) + internal float PlayMusic(string name, bool isLoop = true) { if (_musicSource == null) { _musicSource = _musicParent.AddComponent(); - _musicSource.loop = true; _musicSource.playOnAwake = false; _musicSource.volume = CoreSettings.data.musicVolume * MusicVolume; } @@ -78,6 +77,7 @@ namespace Core.Audio if (_musicAndSounds.ContainsKey(name)) { _musicSource.clip = _musicAndSounds[name]; + _musicSource.loop = isLoop; _musicSource.Play(); return _musicAndSounds[name].length; diff --git a/Assets_DLL/Core/Audio/AudioController3D.cs b/Assets_DLL/Core/Audio/AudioController3D.cs index 33e5c27..51f9f34 100644 --- a/Assets_DLL/Core/Audio/AudioController3D.cs +++ b/Assets_DLL/Core/Audio/AudioController3D.cs @@ -16,10 +16,6 @@ namespace Core.Audio _voicesDictionary = voicesDictionary; } - private GameObject _musicParent = null; - private GameObject _soundsParent = null; - private GameObject _voicesParent = null; - private List _soundsSources = new List(); private List _voicesSources = new List(); @@ -58,9 +54,13 @@ namespace Core.Audio if (playSource == null) { - playSource = _soundsParent.AddComponent(); + GameObject sound = new GameObject("Sound"); + playSource = sound.AddComponent(); playSource.playOnAwake = false; playSource.volume = CoreSettings.data.soundsVolume * SoundsVolume; + playSource.spatialBlend = 1f; + playSource.rolloffMode = AudioRolloffMode.Custom; + playSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0f, 1f, 1f, 0f)); _soundsSources.Add(playSource); } @@ -73,6 +73,9 @@ namespace Core.Audio playSource.maxDistance = maxDistance; playSource.transform.SetParent(target); playSource.transform.localPosition = Vector3.zero; + playSource.spatialBlend = 1f; + playSource.rolloffMode = AudioRolloffMode.Custom; + playSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0f, 1f, 1f, 0f)); playSource.Play(); return _musicAndSounds[name].length; @@ -95,10 +98,14 @@ namespace Core.Audio if (playSource == null) { - playSource = _voicesParent.AddComponent(); + GameObject voice = new GameObject("Voice"); + playSource = voice.AddComponent(); playSource.loop = false; playSource.playOnAwake = false; playSource.volume = CoreSettings.data.voicesVolume * VoicesVolume; + playSource.spatialBlend = 1f; + playSource.rolloffMode = AudioRolloffMode.Custom; + playSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0f, 1f, 1f, 0f)); _voicesSources.Add(playSource); } @@ -112,6 +119,9 @@ namespace Core.Audio playSource.maxDistance = maxDistance; playSource.transform.SetParent(target); playSource.transform.localPosition = Vector3.zero; + playSource.spatialBlend = 1f; + playSource.rolloffMode = AudioRolloffMode.Custom; + playSource.SetCustomCurve(AudioSourceCurveType.CustomRolloff, AnimationCurve.Linear(0f, 1f, 1f, 0f)); playSource.Play(); return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; diff --git a/Assets_DLL/Core/Audio/PlayAudioFile.cs b/Assets_DLL/Core/Audio/PlayAudioFile.cs new file mode 100644 index 0000000..e936b9b --- /dev/null +++ b/Assets_DLL/Core/Audio/PlayAudioFile.cs @@ -0,0 +1,139 @@ +using System.Collections; +using UnityEngine; +using UnityEngine.UI; + +namespace Core.Audio +{ + public sealed class PlayAudioFile : MonoBehaviour + { + public enum SourceType + { + Flat = 0, + Surround = 1, + } + + public enum AudioFileType + { + Music = 0, + Sound = 1, + Voice = 2, + } + + public enum PlayType + { + OnStart = 0, + OnClickButton = 1, + OnClickCollider = 2, + OnPlayParticle = 3, + } + + [SerializeField] private SourceType _sourceType = SourceType.Flat; + [SerializeField] private AudioFileType _audioFileType = AudioFileType.Music; + [SerializeField] private PlayType _playType = PlayType.OnStart; + [SerializeField] private float _startDelay = 0f; + [SerializeField] private bool _loop = false; + [SerializeField] private float _minDistance = 0f; + [SerializeField] private float _maxDistance = 100f; + [SerializeField] private string[] _audioFileNames = new string[0]; + + private ParticleSystem _particleSystem = null; + private Button _button = null; + + private bool _isPlaying = false; + + private void Awake() + { + _button = GetComponent