-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoundManager.cs
172 lines (165 loc) · 4.83 KB
/
SoundManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* Graffiti Softwerks 2022
* SoundManager.cs
* Author: Nash Ali
* Creation Date: 04-23-2022
* Last Update: 04-30-2022
*
* Copyright (c) Graffiti Softwerks 2022
*
*/
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.UI;
public class SoundManager : MonoBehaviour
{
#region defs & vars
[SerializeField]
private AudioSource ambiencePlayer, foleyPlayer, specialfxPlayer;
[SerializeField]
private AudioClip shipNoise, beamNoise, ambEasy, ambMed, ambHard, backgroundMusic, spawnSound;
[SerializeField]
public AudioMixer myMixer;
[SerializeField]
private Slider mainSlider, ambienceSlider, sfxSlider, foleySlider;
#endregion vars
#region MonoBehaviour ************************************************************************
private void Start()
{
myMixer.GetComponent<AudioMixer>();
ambiencePlayer.GetComponent<AudioSource>();
foleyPlayer.GetComponent<AudioSource>();
specialfxPlayer.GetComponent<AudioSource>();
mainSlider.value = PlayerPrefs.GetFloat("MainVolume", mainSlider.value);
ambienceSlider.value = PlayerPrefs.GetFloat("AmbienceVolume", ambienceSlider.value);
sfxSlider.value = PlayerPrefs.GetFloat("SFXVolume", sfxSlider.value);
foleySlider.value = PlayerPrefs.GetFloat("FoleyVolume", sfxSlider.value);
}
#endregion *****************
#region User Code ******************************************************************************
/// <summary>
/// Sets the main volume.
/// </summary>
/// <param name="sliderVolume"></param>
public void SetMainVolume(float sliderVolume)
{
_ = myMixer.SetFloat("MasterVolume", Mathf.Log10(sliderVolume) * 30);
}
/// <summary>
/// Clears the main volume back to the last snapshot.
/// </summary>
public void ClearMainVolume()
{
_ = myMixer.ClearFloat("MasterVolume");
}
/// <summary>
/// Sets the Ambience volume level
/// </summary>
/// <param name="sliderVolume"></param>
public void SetAmbienceVolume(float sliderVolume)
{
_ = myMixer.SetFloat("AmbienceVolume", sliderVolume);
}
/// <summary>
/// goes back to the last snapshot
/// </summary>
public void ClearAmbienceVolume()
{
_ = myMixer.ClearFloat("AmbienceVolume");
}
/// <summary>
/// Set the SFX volume
/// </summary>
/// <param name="sliderVolume"></param>
public void SetSFXVolume(float sliderVolume)
{
_ = myMixer.SetFloat("SFXVolume", sliderVolume);
}
/// <summary>
/// goes back to the last snapshot
/// </summary>
public void ClearSFXVolume()
{
_ = myMixer.ClearFloat("SFXVolume");
}
/// <summary>
/// Set the SFX volume
/// </summary>
/// <param name="sliderVolume"></param>
public void SetFoleyVolume(float sliderVolume)
{
_ = myMixer.SetFloat("FoleyVolume", sliderVolume);
}
/// <summary>
/// goes back to the last snapshot
/// </summary>
public void ClearFoleyVolume()
{
_ = myMixer.ClearFloat("FoleyVolume");
}
/// <summary>
/// Play the easy ambience music
/// </summary>
public void PlayAmbienceEasy()
{
ambiencePlayer.loop = true;
ambiencePlayer.Play();
}
/// <summary>
/// Play the medium level ambience music
/// </summary>
public void PlayAmbienceMedium()
{
ambiencePlayer.loop = true;
ambiencePlayer.Play();
}
/// <summary>
/// plays the hard ambience music.
/// </summary>
public void PlayAmbienceHard()
{
ambiencePlayer.loop = true;
ambiencePlayer.Play();
}
/// <summary>
/// play spawn sound - one shot
/// </summary>
public void PlaySpawnSound()
{
specialfxPlayer.PlayOneShot(spawnSound);
}
/// <summary>
/// play ufo arriving
/// </summary>
public void UfoArrive()
{
specialfxPlayer.PlayOneShot(shipNoise);
}
/// <summary>
/// Play the transport sound.
/// </summary>
public void BeamMeUpSound()
{
specialfxPlayer.PlayOneShot(beamNoise);
}
/// <summary>
/// play the sfx specified
/// </summary>
/// <param name="sfx"></param>
public void PlaySFX(AudioClip sfx)
{
specialfxPlayer.PlayOneShot(sfx);
}
/// <summary>
/// play the foley specified.
/// </summary>
/// <param name="foley"></param>
public void PlayFoley(AudioClip foley)
{
foleyPlayer.PlayOneShot(foley);
}
#endregion *******************************************************
}