init
This commit is contained in:
commit
3b4c6e0ec6
506 changed files with 434142 additions and 0 deletions
71
Assets/Scripts/AudioManager/AudioManager.cs
Normal file
71
Assets/Scripts/AudioManager/AudioManager.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class AudioManager : MonoBehaviour{
|
||||
|
||||
[SerializeField] Sound[] sounds = default;
|
||||
|
||||
public static AudioManager instance;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Awake(){
|
||||
if(instance == null){
|
||||
instance = this;
|
||||
}else{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
foreach(Sound s in sounds){
|
||||
s.source = gameObject.AddComponent<AudioSource>();
|
||||
s.source.clip = s.clip;
|
||||
|
||||
s.source.volume = s.volume;
|
||||
s.source.pitch = s.pitch;
|
||||
s.source.loop = s.loop;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
public void PlayOneShot(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
|
||||
public void Stop(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.Stop();
|
||||
}
|
||||
|
||||
public void PlayWithRandomPitch(string name){
|
||||
Sound s = Array.Find(sounds, sound => sound.name == name);
|
||||
if (s == null){
|
||||
Debug.LogWarning("Sound: " + name + " not found!");
|
||||
return;
|
||||
}
|
||||
|
||||
s.source.volume = s.volume * (1f + UnityEngine.Random.Range(-s.volumeVariance / 2f, s.volumeVariance / 2f));
|
||||
s.source.pitch = s.pitch * (1f + UnityEngine.Random.Range(-s.pitchVariance / 2f, s.pitchVariance / 2f));
|
||||
s.source.PlayOneShot(s.clip);
|
||||
}
|
||||
}
|
11
Assets/Scripts/AudioManager/AudioManager.cs.meta
Normal file
11
Assets/Scripts/AudioManager/AudioManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6ad4d560a5e7c24480d454ea82006f9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
17
Assets/Scripts/AudioManager/Sound.cs
Normal file
17
Assets/Scripts/AudioManager/Sound.cs
Normal file
|
@ -0,0 +1,17 @@
|
|||
using UnityEngine;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound{
|
||||
public string name;
|
||||
|
||||
public AudioClip clip;
|
||||
|
||||
[Range(0f, 1f)] public float volume;
|
||||
[Range(0f, 1f)] public float volumeVariance;
|
||||
[Range(.1f, 3f)] public float pitch;
|
||||
[Range(0f, 1f)] public float pitchVariance;
|
||||
|
||||
public bool loop;
|
||||
|
||||
[HideInInspector] public AudioSource source;
|
||||
}
|
11
Assets/Scripts/AudioManager/Sound.cs.meta
Normal file
11
Assets/Scripts/AudioManager/Sound.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 42f73f4d81953754c96cc4e7a2a7bed5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue