migration from new repo
This commit is contained in:
commit
423134a840
26930 changed files with 3458568 additions and 0 deletions
168
Assets/_/Features/AudioSystem/Runtime/AudioManager.cs
Normal file
168
Assets/_/Features/AudioSystem/Runtime/AudioManager.cs
Normal file
|
|
@ -0,0 +1,168 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Core.Runtime;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AudioSystem.Runtime
|
||||
{
|
||||
public class AudioManager : BaseMonobehaviour
|
||||
{
|
||||
|
||||
#region Publics
|
||||
|
||||
public static AudioManager Instance { get; private set; }
|
||||
|
||||
public enum AudioChannel
|
||||
{
|
||||
Master,
|
||||
Music,
|
||||
SFX,
|
||||
Ambiance
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Unity API
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
_sfxSource = gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Main Methods
|
||||
|
||||
public void PlayLevelMusic()
|
||||
{
|
||||
if (_levelMusic != null)
|
||||
{
|
||||
PlayMusic(_levelMusic, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlaySFX(AudioClip clip)
|
||||
{
|
||||
if(clip == null) return;
|
||||
_sfxSource.PlayOneShot(clip);
|
||||
}
|
||||
|
||||
public void PlaySFXByName(string name)
|
||||
{
|
||||
AudioClip clip = _sfxLibrary.FirstOrDefault(c => c.name == name);
|
||||
if (clip != null)
|
||||
{
|
||||
PlaySFX(clip);
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMusic(AudioClip clip, bool loop = true)
|
||||
{
|
||||
if(clip == null) return;
|
||||
_musicSource.clip = clip;
|
||||
_musicSource.loop = loop;
|
||||
_musicSource.Play();
|
||||
}
|
||||
|
||||
public void PlayAmbiance(AudioClip clip, bool loop = true)
|
||||
{
|
||||
if(clip == null) return;
|
||||
_ambianceSource.clip = clip;
|
||||
_ambianceSource.loop = true;
|
||||
_ambianceSource.Play();
|
||||
}
|
||||
|
||||
public void SetMasterVolume(float value)
|
||||
{
|
||||
if (_audioMixer != null)
|
||||
{
|
||||
_audioMixer.SetFloat("MasterVolume", Mathf.Log10(Mathf.Clamp(value, 0.0001f, 1)) * 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMusicVolume(float value)
|
||||
{
|
||||
if (_audioMixer != null)
|
||||
{
|
||||
_audioMixer.SetFloat("MusicVolume", Mathf.Log10(Mathf.Clamp(value, 0.0001f, 1)) * 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSFXVolume(float value)
|
||||
{
|
||||
if (_audioMixer != null)
|
||||
{
|
||||
_audioMixer.SetFloat("SFXVolume", Mathf.Log10(Mathf.Clamp(value, 0.0001f, 1)) * 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAmbianceVolume(float value)
|
||||
{
|
||||
if (_audioMixer != null)
|
||||
{
|
||||
_audioMixer.SetFloat("AmbianceVolume", Mathf.Log10(Mathf.Clamp(value, 0.0001f, 1)) * 20);
|
||||
}
|
||||
}
|
||||
|
||||
public void BinderVolume(Slider slider, AudioChannel channel)
|
||||
{
|
||||
if(slider == null) return;
|
||||
|
||||
switch (channel)
|
||||
{
|
||||
case AudioChannel.Master:
|
||||
slider.onValueChanged.AddListener(SetMasterVolume);
|
||||
break;
|
||||
case AudioChannel.Music:
|
||||
slider.onValueChanged.AddListener(SetMusicVolume);
|
||||
break;
|
||||
case AudioChannel.SFX:
|
||||
slider.onValueChanged.AddListener(SetSFXVolume);
|
||||
break;
|
||||
case AudioChannel.Ambiance:
|
||||
slider.onValueChanged.AddListener(SetAmbianceVolume);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Utils
|
||||
|
||||
/* Fonctions privées utiles */
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Privates and Protected
|
||||
|
||||
[Header("Source audio du level")]
|
||||
[SerializeField] private AudioClip _levelMusic;
|
||||
|
||||
[Header("Audio Sources")]
|
||||
[SerializeField] private AudioSource _musicSource;
|
||||
[SerializeField] private AudioSource _ambianceSource;
|
||||
[SerializeField] private List<AudioClip> _sfxLibrary;
|
||||
|
||||
[Header("Mixer (Optional)")]
|
||||
[SerializeField] private AudioMixer _audioMixer;
|
||||
|
||||
private AudioSource _sfxSource;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf71e6ed782e4713b95188fa52438cd0
|
||||
timeCreated: 1751220977
|
||||
80
Assets/_/Features/AudioSystem/Runtime/LevelAudioHandler.cs
Normal file
80
Assets/_/Features/AudioSystem/Runtime/LevelAudioHandler.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Core.Runtime
|
||||
{
|
||||
public class SceneLoader : BaseMonobehaviour
|
||||
{
|
||||
|
||||
#region Publics
|
||||
|
||||
public static event Action<Scene> OnSceneLoaded;
|
||||
public static string CurrentSceneName => SceneManager.GetActiveScene().name;
|
||||
public static SceneLoader Instance { get; private set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Unity API
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
SceneManager.sceneLoaded += HandleSceneLoaded;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
SceneManager.sceneLoaded -= HandleSceneLoaded;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Main Methods
|
||||
|
||||
public void LoadScene(string sceneName)
|
||||
{
|
||||
SceneManager.LoadScene(sceneName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Utils
|
||||
|
||||
private void HandleSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
{
|
||||
OnSceneLoaded?.Invoke(scene);
|
||||
}
|
||||
|
||||
private bool SceneExists(string sceneName)
|
||||
{
|
||||
for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
|
||||
{
|
||||
string path = SceneUtility.GetScenePathByBuildIndex(i);
|
||||
string name = System.IO.Path.GetFileNameWithoutExtension(path);
|
||||
if (name == sceneName)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Privates and Protected
|
||||
|
||||
//
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b6d9171f0555419780642bfda5037221
|
||||
timeCreated: 1751223652
|
||||
Loading…
Add table
Add a link
Reference in a new issue