Documentation for the Unity C# Library
Loading...
Searching...
No Matches
EazySoundManagerDemo.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
4
5public class EazySoundManagerDemo : MonoBehaviour
6{
8 public Slider globalVolSlider;
9 public Slider globalMusicVolSlider;
10 public Slider globalSoundVolSlider;
11
12 public GameObject test;
13
14 private void Update ()
15 {
16 // Update UI
17 for(int i=0; i < AudioControls.Length; i++)
18 {
20 if (audioControl.audio != null && audioControl.audio.IsPlaying)
21 {
22 if (audioControl.pauseButton != null)
23 {
24 audioControl.playButton.interactable = false;
25 audioControl.pauseButton.interactable = true;
26 audioControl.stopButton.interactable = true;
27 audioControl.pausedStatusTxt.enabled = false;
28 }
29 }
30 else if (audioControl.audio != null && audioControl.audio.Paused)
31 {
32 if (audioControl.pauseButton != null)
33 {
34 audioControl.playButton.interactable = true;
35 audioControl.pauseButton.interactable = false;
36 audioControl.stopButton.interactable = false;
37 audioControl.pausedStatusTxt.enabled = true;
38 }
39 }
40 else
41 {
42 if (audioControl.pauseButton != null)
43 {
44 audioControl.playButton.interactable = true;
45 audioControl.pauseButton.interactable = false;
46 audioControl.stopButton.interactable = false;
47 audioControl.pausedStatusTxt.enabled = false;
48 }
49 }
50 }
51 }
52
53 public void PlayMusic1()
54 {
56
57 if (audioControl.audio == null)
58 {
59 int audioID = EazySoundManager.PlayMusic(audioControl.audioclip, audioControl.volumeSlider.value, true, false);
61 }
62 else if (audioControl.audio != null && audioControl.audio.Paused)
63 {
64 audioControl.audio.Resume();
65 }
66 else
67 {
68 audioControl.audio.Play();
69 }
70 }
71
72 public void PlayMusic2()
73 {
75
76 if (audioControl.audio == null)
77 {
78 int audioID = EazySoundManager.PlayMusic(audioControl.audioclip, audioControl.volumeSlider.value, true, false);
80 }
81 else if (audioControl.audio != null && audioControl.audio.Paused)
82 {
83 audioControl.audio.Resume();
84 }
85 else
86 {
87 audioControl.audio.Play();
88 }
89 }
90
91 public void Pause(string audioControlIDStr)
92 {
93 int audioControlID = int.Parse(audioControlIDStr);
94 EazySoundDemoAudioControls audioControl = AudioControls[audioControlID];
95
96 audioControl.audio.Pause();
97 }
98
99 public void Stop(string audioControlIDStr)
100 {
101 int audioControlID = int.Parse(audioControlIDStr);
102 EazySoundDemoAudioControls audioControl = AudioControls[audioControlID];
103
104 audioControl.audio.Stop();
105 }
106
107 public void AudioVolumeChanged(string audioControlIDStr)
108 {
109 int audioControlID = int.Parse(audioControlIDStr);
110 EazySoundDemoAudioControls audioControl = AudioControls[audioControlID];
111
112 if (audioControl.audio != null)
113 {
114 audioControl.audio.SetVolume(audioControl.volumeSlider.value, 0);
115 }
116 }
117
119 {
120 EazySoundManager.GlobalVolume = globalVolSlider.value;
121 }
122
124 {
125 EazySoundManager.GlobalMusicVolume = globalMusicVolSlider.value;
126 }
127
129 {
130 EazySoundManager.GlobalSoundsVolume = globalSoundVolSlider.value;
131 }
132}
133
134[System.Serializable]
135public struct EazySoundDemoAudioControls
136{
137 public AudioClip audioclip;
138 public Audio audio;
139 public Button playButton;
140 public Button pauseButton;
141 public Button stopButton;
142 public Slider volumeSlider;
143 public Text pausedStatusTxt;
void Pause(string audioControlIDStr)
EazySoundDemoAudioControls[] AudioControls
void Stop(string audioControlIDStr)
void AudioVolumeChanged(string audioControlIDStr)
The audio object.
Definition Audio.cs:10
void Play()
Start playing audio clip from the beginning.
Definition Audio.cs:407
bool IsPlaying
Whether the audio is currently playing.
Definition Audio.cs:26
bool Paused
Whether the audio is paused.
Definition Audio.cs:31
void Stop()
Stop playing audio clip.
Definition Audio.cs:448
void Pause()
Pause playing audio clip.
Definition Audio.cs:460
void SetVolume(float volume)
Sets the audio volume.
Definition Audio.cs:488
void Resume()
Resume playing audio clip.
Definition Audio.cs:478
Static class responsible for playing and managing audio and sounds.
static int PlayMusic(AudioClip clip)
Play background music.
static Audio GetAudio(int audioID)
Returns the Audio that has as its id the audioID if one is found, returns null if no such Audio is fo...