new audio manager
This commit is contained in:
39
Assets/Scripts/AudioManager.cs
Normal file
39
Assets/Scripts/AudioManager.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
public class AudioManager : MonoBehaviour
|
||||
{
|
||||
public AudioMixer audioMixer;
|
||||
public Sound[] sounds;
|
||||
|
||||
private void Awake() {
|
||||
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;
|
||||
|
||||
s.source.outputAudioMixerGroup = s.outputMixer;
|
||||
}
|
||||
}
|
||||
|
||||
public void Play(string name){
|
||||
Sound s = Array.Find(sounds, sounds => sounds.name == name);
|
||||
s.source.Play();
|
||||
}
|
||||
|
||||
public void SetMainVolume(float mainVolume) {
|
||||
audioMixer.SetFloat("Master", mainVolume);
|
||||
}
|
||||
public void SetMusicVolume(float musicVolume) {
|
||||
audioMixer.SetFloat("Music", musicVolume);
|
||||
}
|
||||
public void SetSfxVolume(float sfxVolume) {
|
||||
audioMixer.SetFloat("Sfx", sfxVolume);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/AudioManager.cs.meta
Normal file
11
Assets/Scripts/AudioManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc69655c5f792d9dab9db9dc72d26e93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Assets/Scripts/Sound.cs
Normal file
19
Assets/Scripts/Sound.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Audio;
|
||||
|
||||
[System.Serializable]
|
||||
public class Sound
|
||||
{
|
||||
public string name;
|
||||
public AudioClip clip;
|
||||
[Range(0f, 1f)]
|
||||
public float volume;
|
||||
[Range(0.1f, 3f)]
|
||||
public float pitch;
|
||||
public bool loop;
|
||||
[HideInInspector]
|
||||
public AudioSource source;
|
||||
public AudioMixerGroup outputMixer;
|
||||
}
|
||||
11
Assets/Scripts/Sound.cs.meta
Normal file
11
Assets/Scripts/Sound.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bad3c18e1bd9a55da1a52c7588f21fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -36,6 +36,7 @@ public class jatekmanager : MonoBehaviour
|
||||
private TurnManager turnManager;
|
||||
private Source source;
|
||||
private vegpontozas vegpontozas;
|
||||
private AudioManager audioManager;
|
||||
|
||||
//ügynökcsapatok implementálása
|
||||
public TMP_Text[] oneone;
|
||||
@@ -64,6 +65,10 @@ public class jatekmanager : MonoBehaviour
|
||||
private void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
//hatterzene lejatszas
|
||||
audioManager = FindObjectOfType<AudioManager>();
|
||||
audioManager.Play("BackgroundMusic");
|
||||
}
|
||||
|
||||
private void Start()
|
||||
|
||||
@@ -10,6 +10,16 @@ public class MainMenu : MonoBehaviour
|
||||
public GameObject CreditsMenuObj;
|
||||
public GameObject VideoButton;
|
||||
|
||||
private AudioManager audioManager;
|
||||
|
||||
private void Awake() {
|
||||
audioManager = FindObjectOfType<AudioManager>();
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
audioManager.Play("MenuMusic");
|
||||
}
|
||||
|
||||
public void PlayGame()
|
||||
{
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
|
||||
|
||||
@@ -38,19 +38,6 @@ public class OptionMenu : MonoBehaviour
|
||||
Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen);
|
||||
}
|
||||
|
||||
//Audio
|
||||
public AudioMixer mixer;
|
||||
|
||||
public void SetMainVolume(float mainVolume) {
|
||||
mixer.SetFloat("Master", mainVolume);
|
||||
}
|
||||
public void SetMusicVolume(float musicVolume) {
|
||||
mixer.SetFloat("Music", musicVolume);
|
||||
}
|
||||
public void SetSfxVolume(float sfxVolume) {
|
||||
mixer.SetFloat("Sfx", sfxVolume);
|
||||
}
|
||||
|
||||
//Quality
|
||||
public void setQuality(int qualityIndex) {
|
||||
QualitySettings.SetQualityLevel(qualityIndex);
|
||||
|
||||
Reference in New Issue
Block a user