Browse Source

- Prototype ver.1.8.3

3D AudioController
master
Seraph 4 years ago
parent
commit
f051307d56
  1. BIN
      Assets/Prototype/Core/Core.dll
  2. BIN
      Assets/Prototype/Core/CoreEditor.dll
  3. 43
      Assets_DLL/Core/Audio/AudioController.cs
  4. 22
      Assets_DLL/Core/Audio/AudioController2D.cs
  5. 134
      Assets_DLL/Core/Audio/AudioController3D.cs
  6. 10
      Assets_DLL/Core/IAP/PurchaseButton.cs
  7. 31
      Assets_DLL/Core/Tools/BufferManager.cs
  8. BIN
      Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache
  9. 2
      Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache
  10. BIN
      Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll
  11. 6
      Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs
  12. 4
      Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs
  13. 4
      Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs
  14. BIN
      Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache
  15. BIN
      Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll
  16. BIN
      Builds/Core_1.8.3.unitypackage

BIN
Assets/Prototype/Core/Core.dll

Binary file not shown.

BIN
Assets/Prototype/Core/CoreEditor.dll

Binary file not shown.

43
Assets_DLL/Core/Audio/AudioController.cs

@ -7,21 +7,24 @@ using Core.Tools.Saves;
namespace Core.Audio namespace Core.Audio
{ {
public static class AudioController public class AudioController : MonoBehaviour
{ {
private static AudioController2D _audio2D = null; private static AudioController2D _audio2D = null;
private static AudioController3D _audio3D = null;
internal static void Init() internal static void Init()
{ {
GameObject audioParent = new GameObject("[AudioController]"); GameObject audioParent = new GameObject("[AudioController]");
audioParent.AddComponent<AudioController>();
GameObject.DontDestroyOnLoad(audioParent); GameObject.DontDestroyOnLoad(audioParent);
Dictionary<string, AudioClip> musicAnsSoundsDictionary = new Dictionary<string, AudioClip>(); Dictionary<string, AudioClip> musicAnsSoundsDictionary = new Dictionary<string, AudioClip>();
Dictionary<SystemLanguage, Dictionary<string, AudioClip>> languageVoicesDictionary = new Dictionary<SystemLanguage, Dictionary<string, AudioClip>>(); Dictionary<SystemLanguage, Dictionary<string, AudioClip>> languageVoicesDictionary = new Dictionary<SystemLanguage, Dictionary<string, AudioClip>>();
AudioClip[] music = Resources.LoadAll<AudioClip>("CoreAudio/Musics"); AudioClip[] music = Resources.LoadAll<AudioClip>("Audio/Musics");
AudioClip[] sounds = Resources.LoadAll<AudioClip>("CoreAudio/Sounds"); AudioClip[] sounds = Resources.LoadAll<AudioClip>("Audio/Sounds");
for (int i = 0; i < music.Length; i++) for (int i = 0; i < music.Length; i++)
musicAnsSoundsDictionary.Add(music[i].name, music[i]); musicAnsSoundsDictionary.Add(music[i].name, music[i]);
@ -45,6 +48,9 @@ namespace Core.Audio
_audio2D = new AudioController2D(); _audio2D = new AudioController2D();
_audio2D.Init(audioParent.transform, musicAnsSoundsDictionary, languageVoicesDictionary); _audio2D.Init(audioParent.transform, musicAnsSoundsDictionary, languageVoicesDictionary);
_audio3D = new AudioController3D();
_audio3D.Init(audioParent.transform, musicAnsSoundsDictionary, languageVoicesDictionary);
} }
public static float MusicVolume public static float MusicVolume
@ -86,13 +92,40 @@ namespace Core.Audio
public static float PlaySound(string name, bool isLoop = false) => public static float PlaySound(string name, bool isLoop = false) =>
_audio2D.PlaySound(name, isLoop); _audio2D.PlaySound(name, isLoop);
public static void StopSound(string name) => public static void StopSound(string name)
{
_audio2D.StopSound(name); _audio2D.StopSound(name);
_audio3D.StopSound(name);
}
public static float PlayVoice(string name) => public static float PlayVoice(string name) =>
_audio2D.PlayVoice(name); _audio2D.PlayVoice(name);
public static void StopVoice(string name) => public static void StopVoice(string name)
{
_audio2D.StopVoice(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<AudioListener>();
if (listener == null)
_currentTarget = listener.transform;
}
else
transform.position = _currentTarget.position;
}
} }
} }

22
Assets_DLL/Core/Audio/AudioController2D.cs

@ -4,6 +4,7 @@ using System.Linq;
using UnityEngine; using UnityEngine;
using Core.Settings; using Core.Settings;
using Core.Tools.Saves; using Core.Tools.Saves;
using System;
namespace Core.Audio namespace Core.Audio
{ {
@ -82,10 +83,7 @@ namespace Core.Audio
return _musicAndSounds[name].length; return _musicAndSounds[name].length;
} }
else else
{ throw new ArgumentNullException($"music \"{name}\" not found");
Debug.LogError($"AudioController: music \"{name}\" not found");
return 0f;
}
} }
internal void StopMusic() internal void StopMusic()
@ -100,7 +98,6 @@ namespace Core.Audio
if (playSource == null) if (playSource == null)
{ {
playSource = _soundsParent.AddComponent<AudioSource>(); playSource = _soundsParent.AddComponent<AudioSource>();
playSource.loop = false;
playSource.playOnAwake = false; playSource.playOnAwake = false;
playSource.volume = CoreSettings.data.soundsVolume * SoundsVolume; playSource.volume = CoreSettings.data.soundsVolume * SoundsVolume;
@ -116,10 +113,7 @@ namespace Core.Audio
return _musicAndSounds[name].length; return _musicAndSounds[name].length;
} }
else else
{ throw new ArgumentNullException($"sound \"{name}\" not found");
Debug.LogError($"AudioController: sound \"{name}\" not found");
return 0f;
}
} }
internal void StopSound(string name) internal void StopSound(string name)
@ -154,16 +148,10 @@ namespace Core.Audio
return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length; return _voicesDictionary[LocalizationManager.CurrentLanguage][name].length;
} }
else else
{ throw new ArgumentNullException($"voice \"{name}\" not found");
Debug.LogError($"AudioController: voice \"{name}\" not found");
return 0f;
}
} }
else else
{ throw new ArgumentNullException($"Avoice \"{name}\" not found");
Debug.LogError($"AudioController: voice \"{name}\" not found");
return 0f;
}
} }
internal void StopVoice(string name) internal void StopVoice(string name)

134
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<string, AudioClip> musicAnsSounds, Dictionary<SystemLanguage, Dictionary<string, AudioClip>> voicesDictionary)
{
_musicAndSounds = musicAnsSounds;
_voicesDictionary = voicesDictionary;
}
private GameObject _musicParent = null;
private GameObject _soundsParent = null;
private GameObject _voicesParent = null;
private List<AudioSource> _soundsSources = new List<AudioSource>();
private List<AudioSource> _voicesSources = new List<AudioSource>();
private Dictionary<string, AudioClip> _musicAndSounds = new Dictionary<string, AudioClip>();
private Dictionary<SystemLanguage, Dictionary<string, AudioClip>> _voicesDictionary = new Dictionary<SystemLanguage, Dictionary<string, AudioClip>>();
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<AudioSource>();
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<AudioSource>();
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();
}
}
}

10
Assets_DLL/Core/IAP/PurchaseButton.cs

@ -11,6 +11,7 @@ namespace Core.Ads
public sealed class PurchaseButton : MonoBehaviour public sealed class PurchaseButton : MonoBehaviour
{ {
[SerializeField] private string _productId = ""; [SerializeField] private string _productId = "";
[SerializeField] private Text _priceText = null;
[SerializeField] private UnityEvent _onSucces = null; [SerializeField] private UnityEvent _onSucces = null;
[SerializeField] private UnityEvent _onFailed = null; [SerializeField] private UnityEvent _onFailed = null;
@ -26,6 +27,9 @@ namespace Core.Ads
private void OnEnable() private void OnEnable()
{ {
if (_priceText != null)
_priceText.text = PurchaseManager.GetLocalizedPrice(_productId);
PurchaseManager.OnPurchaseSuccess += CheckAdsEnablingAfterPurchasing; PurchaseManager.OnPurchaseSuccess += CheckAdsEnablingAfterPurchasing;
PurchaseManager.OnPurchaseFailed += PurchaseManager_OnPurchaseFailed; PurchaseManager.OnPurchaseFailed += PurchaseManager_OnPurchaseFailed;
@ -41,10 +45,12 @@ namespace Core.Ads
private void CheckAdsEnablingAfterPurchasing(string productId) private void CheckAdsEnablingAfterPurchasing(string productId)
{ {
if (_productId == productId && !CoreSettings.data.IsProductConsumable(productId)) if (_productId == productId)
{ {
_onSucces?.Invoke(); _onSucces?.Invoke();
gameObject.SetActive(false);
if (!CoreSettings.data.IsProductConsumable(productId))
gameObject.SetActive(false);
} }
} }

31
Assets_DLL/Core/Tools/BufferManager.cs

@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace Core.Tools
{
public static class BufferManager
{
private static Dictionary<string, object> _buffer = new Dictionary<string, object>();
public static void Add<T>(string key, T element)
{
if (_buffer.ContainsKey(key))
_buffer[key] = element;
else
_buffer.Add(key, element);
}
public static T Get<T>(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);
}
}
}

BIN
Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.AssemblyReference.cache

Binary file not shown.

2
Assets_DLL/Core/obj/Debug/netstandard2.0/Core.csproj.CoreCompileInputs.cache

@ -1 +1 @@
049145f5314f464185eb4974b4434a906bbba395 7fd1797d3498be18a922a7bf796a7fa6c67322c0

BIN
Assets_DLL/Core/obj/Debug/netstandard2.0/Core.dll

Binary file not shown.

6
Assets_DLL/CoreEditor/IAP/PurchaseButtonEditor.cs

@ -2,6 +2,7 @@
using Core.Settings; using Core.Settings;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine.UI;
namespace CoreEditor.Localization namespace CoreEditor.Localization
{ {
@ -15,6 +16,7 @@ namespace CoreEditor.Localization
EditorGUILayout.Space(5); EditorGUILayout.Space(5);
SerializedProperty productId = serializedObject.FindProperty("_productId"); SerializedProperty productId = serializedObject.FindProperty("_productId");
SerializedProperty priceText = serializedObject.FindProperty("_priceText");
List<string> products = new List<string>(); List<string> products = new List<string>();
@ -42,6 +44,10 @@ namespace CoreEditor.Localization
currentIndex = EditorGUILayout.Popup("Product ID:", currentIndex, products.ToArray()); 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]; productId.stringValue = products[currentIndex];
EditorGUILayout.Space(10); EditorGUILayout.Space(10);

4
Assets_DLL/CoreEditor/Tools/Pool/Particles/ParticlesPoolEditor.cs

@ -18,7 +18,7 @@ namespace CoreEditor.Localization
EditorGUILayout.BeginHorizontal("BOX"); EditorGUILayout.BeginHorizontal("BOX");
GUILayout.Label("ID", EditorStyles.label); 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("StartCount", EditorStyles.label, GUILayout.MaxWidth(64));
GUILayout.Label("", 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); id.stringValue = EditorGUILayout.TextField(id.stringValue);
prefab.objectReferenceValue = (ParticleSystem)EditorGUILayout.ObjectField((ParticleSystem)prefab.objectReferenceValue, typeof(ParticleSystem), true);
EditorGUILayout.PropertyField(prefab, GUIContent.none); EditorGUILayout.PropertyField(prefab, GUIContent.none);
count.intValue = EditorGUILayout.IntField(count.intValue, GUILayout.MaxWidth(64)); count.intValue = EditorGUILayout.IntField(count.intValue, GUILayout.MaxWidth(64));

4
Assets_DLL/CoreEditor/Tools/UnusedAssetsMarker.cs

@ -99,13 +99,13 @@ namespace Core.Tools
newRect.x += rect.width - 305; newRect.x += rect.width - 305;
newRect.width = 200; newRect.width = 200;
GUI.Label(newRect, $"Used assets count: {usedCount}"); GUI.Label(newRect, $"Used: {usedCount}");
newRect = rect; newRect = rect;
newRect.x += rect.width - 155; newRect.x += rect.width - 155;
newRect.width = 200; newRect.width = 200;
GUI.Label(newRect, $"Unused assets count: {unusedCount}"); GUI.Label(newRect, $"Unused: {unusedCount}");
} }
GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.white;

BIN
Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.csproj.AssemblyReference.cache

Binary file not shown.

BIN
Assets_DLL/CoreEditor/obj/Debug/netstandard2.0/CoreEditor.dll

Binary file not shown.

BIN
Builds/Core_1.8.3.unitypackage

Binary file not shown.
Loading…
Cancel
Save