init
This commit is contained in:
commit
001bb14f16
951 changed files with 270074 additions and 0 deletions
196
Assets/Tools/AudioManager/AudioManager.cs
Normal file
196
Assets/Tools/AudioManager/AudioManager.cs
Normal file
|
@ -0,0 +1,196 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
[SerializeField] Sounds soundList = default;
|
||||
|
||||
void Awake(){
|
||||
if(instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach(Sounds.List s in soundList.sounds){
|
||||
GameObject sound = new GameObject(s.name);
|
||||
sound.transform.parent = transform;
|
||||
s.source = sound.AddComponent<AudioSource>();
|
||||
|
||||
if(soundList.mainMixer && soundList.sfxMixer){
|
||||
if (s.type == Sounds.List.Type.Music)
|
||||
s.source.outputAudioMixerGroup = soundList.mainMixer;
|
||||
else
|
||||
s.source.outputAudioMixerGroup = soundList.sfxMixer;
|
||||
}
|
||||
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = (s.volume.x + s.volume.y) / 2;
|
||||
s.source.pitch = (s.pitch.x + s.pitch.y) / 2;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if(s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Play();
|
||||
}
|
||||
public void Play(string name, float delay){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.PlayDelayed(delay);
|
||||
}
|
||||
public void PlayOneShot(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
public void Pause(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Pause();
|
||||
}
|
||||
public void UnPause(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.UnPause();
|
||||
}
|
||||
public void Stop(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = s.RandomVolume;
|
||||
s.source.Stop();
|
||||
}
|
||||
public void StopAll(){
|
||||
foreach (Sounds.List s in soundList.sounds){
|
||||
if (s.source){
|
||||
s.source.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public AudioSource GetSource(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return null;
|
||||
}
|
||||
return s.source;
|
||||
}
|
||||
|
||||
public void FadeIn(string name, float duration){
|
||||
StartCoroutine(FadeInCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeInCoroutine(string name, float fadeTime){
|
||||
AudioSource audioSource = GetSource(name);
|
||||
if (audioSource != null && !audioSource.isPlaying){
|
||||
float volume = audioSource.volume;
|
||||
audioSource.volume = 0;
|
||||
audioSource.Play();
|
||||
while (audioSource.volume < volume){
|
||||
audioSource.volume += Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.volume = volume;
|
||||
}
|
||||
}
|
||||
public void FadeOut(string name, float duration){
|
||||
StartCoroutine(FadeOutCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeOutCoroutine(string name, float fadeTime){
|
||||
AudioSource audioSource = GetSource(name);
|
||||
|
||||
if (audioSource && audioSource.isPlaying){
|
||||
float startVolume = audioSource.volume;
|
||||
|
||||
while (audioSource.volume > 0){
|
||||
audioSource.volume -= startVolume * Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
audioSource.Stop();
|
||||
audioSource.volume = startVolume;
|
||||
}
|
||||
}
|
||||
|
||||
public void PlayMuted(string name){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
s.source.pitch = s.RandomPitch;
|
||||
s.source.volume = 0f;
|
||||
s.source.Play();
|
||||
}
|
||||
public void FadeMutedIn(string name, float duration){
|
||||
StartCoroutine(FadeMutedInCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeMutedInCoroutine(string name, float fadeTime){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while (s.source.volume < s.volume.y){
|
||||
s.source.volume += Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = s.volume.y;
|
||||
}
|
||||
public void FadeMutedOut(string name, float duration){
|
||||
StartCoroutine(FadeMutedOutCoroutine(name, duration));
|
||||
}
|
||||
IEnumerator FadeMutedOutCoroutine(string name, float fadeTime){
|
||||
Sounds.List s = Array.Find(soundList.sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
yield break;
|
||||
}
|
||||
|
||||
while (s.source.volume > 0){
|
||||
s.source.volume -= Time.deltaTime / fadeTime;
|
||||
yield return null;
|
||||
}
|
||||
s.source.volume = 0;
|
||||
}
|
||||
}
|
11
Assets/Tools/AudioManager/AudioManager.cs.meta
Normal file
11
Assets/Tools/AudioManager/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7d2879f3876727040b4f0cc799ec7ada
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
51
Assets/Tools/AudioManager/Sounds.cs
Normal file
51
Assets/Tools/AudioManager/Sounds.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using Geri.MinMaxSlider;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
[CreateAssetMenu(fileName = "Sounds", menuName = "Tools/Sounds")]
|
||||
public class Sounds : ScriptableObject{
|
||||
|
||||
[Tooltip("The music mixer.")]
|
||||
public AudioMixerGroup mainMixer = default;
|
||||
[Tooltip("The SFX mixer.")]
|
||||
public AudioMixerGroup sfxMixer = default;
|
||||
|
||||
public List[] sounds;
|
||||
|
||||
[System.Serializable] public class List{
|
||||
[Tooltip("Name of the sound. Each name has to be different between each other.")]
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[System.Serializable] public enum Type { Music, SFX }
|
||||
[Space]
|
||||
[Tooltip("Is it part of the music or the SFX?")] public Type type;
|
||||
|
||||
[Space]
|
||||
[Tooltip("Default volume of the sound."), MinMaxSlider(0f, 1f)] public Vector2 volume;
|
||||
[Tooltip("Default pitch of the sound."), MinMaxSlider(.1f, 3f)] public Vector2 pitch;
|
||||
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
|
||||
float randomVolume;
|
||||
public float RandomVolume{
|
||||
get{
|
||||
randomVolume = Random.Range(volume.x, volume.y);
|
||||
return randomVolume;
|
||||
}
|
||||
}
|
||||
|
||||
float randomPitch;
|
||||
public float RandomPitch{
|
||||
get{
|
||||
randomPitch = Random.Range(pitch.x, pitch.y);
|
||||
return randomPitch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Tools/AudioManager/Sounds.cs.meta
Normal file
11
Assets/Tools/AudioManager/Sounds.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6ded47588579f3047b1c3cd72cd87044
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
BIN
Assets/Tools/AudioManager/d3e5dd010fe84e70ac9cd20fc7d96c97.png
(Stored with Git LFS)
Normal file
BIN
Assets/Tools/AudioManager/d3e5dd010fe84e70ac9cd20fc7d96c97.png
(Stored with Git LFS)
Normal file
Binary file not shown.
|
@ -0,0 +1,130 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 23c2f6dcbe236d044bcf869f85fae215
|
||||
TextureImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 11
|
||||
mipmaps:
|
||||
mipMapMode: 0
|
||||
enableMipMap: 0
|
||||
sRGBTexture: 1
|
||||
linearTexture: 0
|
||||
fadeOut: 0
|
||||
borderMipMap: 0
|
||||
mipMapsPreserveCoverage: 0
|
||||
alphaTestReferenceValue: 0.5
|
||||
mipMapFadeDistanceStart: 1
|
||||
mipMapFadeDistanceEnd: 3
|
||||
bumpmap:
|
||||
convertToNormalMap: 0
|
||||
externalNormalMap: 0
|
||||
heightScale: 0.25
|
||||
normalMapFilter: 0
|
||||
isReadable: 0
|
||||
streamingMipmaps: 0
|
||||
streamingMipmapsPriority: 0
|
||||
vTOnly: 0
|
||||
grayScaleToAlpha: 0
|
||||
generateCubemap: 6
|
||||
cubemapConvolution: 0
|
||||
seamlessCubemap: 0
|
||||
textureFormat: 1
|
||||
maxTextureSize: 2048
|
||||
textureSettings:
|
||||
serializedVersion: 2
|
||||
filterMode: -1
|
||||
aniso: -1
|
||||
mipBias: -100
|
||||
wrapU: 1
|
||||
wrapV: 1
|
||||
wrapW: -1
|
||||
nPOTScale: 0
|
||||
lightmap: 0
|
||||
compressionQuality: 50
|
||||
spriteMode: 1
|
||||
spriteExtrude: 1
|
||||
spriteMeshType: 1
|
||||
alignment: 0
|
||||
spritePivot: {x: 0.5, y: 0.5}
|
||||
spritePixelsToUnits: 100
|
||||
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||
spriteGenerateFallbackPhysicsShape: 1
|
||||
alphaUsage: 1
|
||||
alphaIsTransparency: 1
|
||||
spriteTessellationDetail: -1
|
||||
textureType: 8
|
||||
textureShape: 1
|
||||
singleChannelComponent: 0
|
||||
maxTextureSizeSet: 0
|
||||
compressionQualitySet: 0
|
||||
textureFormatSet: 0
|
||||
ignorePngGamma: 0
|
||||
applyGammaDecoding: 0
|
||||
platformSettings:
|
||||
- serializedVersion: 3
|
||||
buildTarget: DefaultTexturePlatform
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Standalone
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: Android
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
- serializedVersion: 3
|
||||
buildTarget: WebGL
|
||||
maxTextureSize: 2048
|
||||
resizeAlgorithm: 0
|
||||
textureFormat: -1
|
||||
textureCompression: 1
|
||||
compressionQuality: 50
|
||||
crunchedCompression: 0
|
||||
allowsAlphaSplitting: 0
|
||||
overridden: 0
|
||||
androidETC2FallbackOverride: 0
|
||||
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||
spriteSheet:
|
||||
serializedVersion: 2
|
||||
sprites: []
|
||||
outline: []
|
||||
physicsShape: []
|
||||
bones: []
|
||||
spriteID: 5e97eb03825dee720800000000000000
|
||||
internalID: 0
|
||||
vertices: []
|
||||
indices:
|
||||
edges: []
|
||||
weights: []
|
||||
secondaryTextures: []
|
||||
spritePackingTag:
|
||||
pSDRemoveMatte: 0
|
||||
pSDShowRemoveMatteOption: 0
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue