new audio manager

This commit is contained in:
2023-04-13 09:54:21 +02:00
parent 2f1c758137
commit 214f206b01
10 changed files with 220 additions and 193 deletions

View File

@@ -11182,7 +11182,7 @@ GameObject:
- component: {fileID: 519420031}
- component: {fileID: 519420033}
- component: {fileID: 519420035}
- component: {fileID: 519420034}
- component: {fileID: 519420036}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@@ -11281,102 +11281,6 @@ MonoBehaviour:
m_RequiresDepthTexture: 0
m_RequiresColorTexture: 0
m_Version: 2
--- !u!82 &519420034
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: -8278190956376925970, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
m_audioClip: {fileID: 8300000, guid: 0b3a32694c5ed5f4fad733a3945a4249, type: 3}
m_PlayOnAwake: 1
m_Volume: 1
m_Pitch: 1
Loop: 1
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!81 &519420035
AudioListener:
m_ObjectHideFlags: 0
@@ -11385,6 +11289,27 @@ AudioListener:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
--- !u!114 &519420036
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 519420028}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cc69655c5f792d9dab9db9dc72d26e93, type: 3}
m_Name:
m_EditorClassIdentifier:
audioMixer: {fileID: 24100000, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
sounds:
- name: BackgroundMusic
clip: {fileID: 8300000, guid: 0b3a32694c5ed5f4fad733a3945a4249, type: 3}
volume: 1
pitch: 1
loop: 1
source: {fileID: 0}
outputMixer: {fileID: -8278190956376925970, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
--- !u!1 &525047094
GameObject:
m_ObjectHideFlags: 0

View File

@@ -4160,11 +4160,12 @@ GameObject:
m_Component:
- component: {fileID: 1386328419}
- component: {fileID: 1386328418}
- component: {fileID: 1386328417}
- component: {fileID: 1386328422}
- component: {fileID: 1386328426}
- component: {fileID: 1386328425}
- component: {fileID: 1386328423}
- component: {fileID: 1386328426}
- component: {fileID: 1386328417}
- component: {fileID: 1386328427}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
@@ -4284,7 +4285,6 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
resolutionDropdown: {fileID: 415922102}
mixer: {fileID: 24100000, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
--- !u!114 &1386328425
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -4313,6 +4313,26 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: b0fa93b33fed1ce42a3e77548b03decc, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1386328427
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1386328416}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cc69655c5f792d9dab9db9dc72d26e93, type: 3}
m_Name:
m_EditorClassIdentifier:
audioMixer: {fileID: 24100000, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
sounds:
- name: MenuMusic
clip: {fileID: 8300000, guid: 0b3a32694c5ed5f4fad733a3945a4249, type: 3}
volume: 1
pitch: 1
source: {fileID: 0}
outputMixer: {fileID: -8278190956376925970, guid: 833dc20f7f9e5b244a756827a43d874d, type: 2}
--- !u!1 &1421471717
GameObject:
m_ObjectHideFlags: 0
@@ -5591,8 +5611,8 @@ MonoBehaviour:
m_OnValueChanged:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1386328423}
m_TargetAssemblyTypeName: OptionMenu, Assembly-CSharp
- m_Target: {fileID: 1386328427}
m_TargetAssemblyTypeName: AudioManager, Assembly-CSharp
m_MethodName: SetSfxVolume
m_Mode: 0
m_Arguments:
@@ -6399,8 +6419,8 @@ MonoBehaviour:
m_OnValueChanged:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1386328423}
m_TargetAssemblyTypeName: OptionMenu, Assembly-CSharp
- m_Target: {fileID: 1386328427}
m_TargetAssemblyTypeName: AudioManager, Assembly-CSharp
m_MethodName: SetMusicVolume
m_Mode: 0
m_Arguments:
@@ -6638,8 +6658,8 @@ MonoBehaviour:
m_OnValueChanged:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1386328423}
m_TargetAssemblyTypeName: OptionMenu, Assembly-CSharp
- m_Target: {fileID: 1386328427}
m_TargetAssemblyTypeName: AudioManager, Assembly-CSharp
m_MethodName: SetMainVolume
m_Mode: 0
m_Arguments:

View 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);
}
}

View 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
View 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;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2bad3c18e1bd9a55da1a52c7588f21fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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()

View File

@@ -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);

View File

@@ -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);

View File

@@ -15,11 +15,11 @@ MonoBehaviour:
m_PixelRect:
serializedVersion: 2
x: 0
y: 43
width: 1920
height: 997
y: 28
width: 1366
height: 680
m_ShowMode: 4
m_Title: Inspector
m_Title: Game
m_RootView: {fileID: 3}
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
@@ -39,10 +39,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1377
x: 979
y: 0
width: 543
height: 947
width: 387
height: 630
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 17}
@@ -70,8 +70,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1920
height: 997
width: 1366
height: 680
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1
@@ -95,7 +95,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1920
width: 1366
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@@ -116,8 +116,8 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 977
width: 1920
y: 660
width: 1366
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@@ -140,12 +140,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 30
width: 1920
height: 947
width: 1366
height: 630
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 94
controlID: 35
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
@@ -165,12 +165,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1377
height: 947
width: 979
height: 630
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 82
controlID: 21
--- !u!114 &8
MonoBehaviour:
m_ObjectHideFlags: 52
@@ -190,12 +190,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1377
height: 661
width: 979
height: 440
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 83
controlID: 22
--- !u!114 &9
MonoBehaviour:
m_ObjectHideFlags: 52
@@ -213,8 +213,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 228
height: 661
width: 163
height: 440
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 13}
@@ -237,10 +237,10 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 228
x: 163
y: 0
width: 1149
height: 661
width: 816
height: 440
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 14}
@@ -265,11 +265,11 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 661
width: 1377
height: 286
m_MinSize: {x: 101, y: 121}
m_MaxSize: {x: 4001, y: 4021}
y: 440
width: 979
height: 190
m_MinSize: {x: 100, y: 100}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 16}
m_Panes:
- {fileID: 15}
@@ -296,10 +296,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 228
y: 73
width: 1147
height: 640
x: 163
y: 86
width: 814
height: 419
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@@ -310,7 +310,7 @@ MonoBehaviour:
m_ShowGizmos: 0
m_TargetDisplay: 0
m_ClearColor: {r: 0, g: 0, b: 0, a: 0}
m_TargetSize: {x: 1147, y: 619}
m_TargetSize: {x: 814, y: 398}
m_TextureFilterMode: 0
m_TextureHideFlags: 61
m_RenderIMGUI: 1
@@ -325,10 +325,10 @@ MonoBehaviour:
m_VRangeLocked: 0
hZoomLockedByDefault: 0
vZoomLockedByDefault: 0
m_HBaseRangeMin: -573.5
m_HBaseRangeMax: 573.5
m_VBaseRangeMin: -309.5
m_VBaseRangeMax: 309.5
m_HBaseRangeMin: -407
m_HBaseRangeMax: 407
m_VBaseRangeMin: -199
m_VBaseRangeMax: 199
m_HAllowExceedBaseRangeMin: 1
m_HAllowExceedBaseRangeMax: 1
m_VAllowExceedBaseRangeMin: 1
@@ -346,23 +346,23 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 21
width: 1147
height: 619
width: 814
height: 398
m_Scale: {x: 1, y: 1}
m_Translation: {x: 573.5, y: 309.5}
m_Translation: {x: 407, y: 199}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
m_MarginBottom: 0
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -573.5
y: -309.5
width: 1147
height: 619
x: -407
y: -199
width: 814
height: 398
m_MinimalGUI: 1
m_defaultScale: 1
m_LastWindowPixelSize: {x: 1147, y: 640}
m_LastWindowPixelSize: {x: 814, y: 419}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000000000000
@@ -389,19 +389,19 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 73
width: 227
height: 640
y: 86
width: 162
height: 419
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
m_SaveData: []
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 197}
m_SelectedIDs: 886e0000
m_LastClickedID: 28296
m_ExpandedIDs: 0e69ffff6874ffff28fbffff9e700000d4700000287100003675000012780000
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 0afbffff
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -445,10 +445,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 228
y: 73
width: 1147
height: 640
x: 163
y: 86
width: 814
height: 419
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@@ -545,7 +545,7 @@ MonoBehaviour:
containerId: overlay-container--right
floating: 0
collapsed: 0
displayed: 1
displayed: 0
snapOffset: {x: 0, y: 0}
snapOffsetDelta: {x: 0, y: 0}
snapCorner: 0
@@ -698,16 +698,16 @@ MonoBehaviour:
m_WindowGUID: cc27987af1a868c49b0894db9c0f5429
m_Gizmos: 1
m_OverrideSceneCullingMask: 6917529027641081856
m_SceneIsLit: 1
m_SceneIsLit: 0
m_SceneLighting: 1
m_2DMode: 1
m_isRotationLocked: 0
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: -9.559104, y: -0.1136321, z: -0.011797322}
m_Target: {x: -1.8306633, y: -3.2436488, z: 0.12008308}
speed: 2
m_Value: {x: -9.100242, y: -0.020794325, z: -0.016469676}
m_Value: {x: -1.8306633, y: -3.2436488, z: 0.12008308}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
@@ -758,9 +758,9 @@ MonoBehaviour:
speed: 2
m_Value: {x: 0, y: 0, z: 0, w: 1}
m_Size:
m_Target: 9.915714
m_Target: 9.074684
speed: 2
m_Value: 10.382947
m_Value: 9.074684
m_Ortho:
m_Target: 1
speed: 2
@@ -841,7 +841,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: 3e7a0000
m_LastClickedID: 31294
m_ExpandedIDs: 000000001a7a00003a7a0000487a0000
m_ExpandedIDs: 00000000407a0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -869,7 +869,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 000000001a7a0000
m_ExpandedIDs: 00000000407a0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@@ -946,9 +946,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: 0
y: 734
width: 1376
height: 265
y: 526
width: 978
height: 169
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@@ -973,10 +973,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1377
y: 73
width: 542
height: 926
x: 979
y: 86
width: 386
height: 609
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default