-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmbientAudio.cs
More file actions
88 lines (70 loc) · 2.24 KB
/
AmbientAudio.cs
File metadata and controls
88 lines (70 loc) · 2.24 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AmbientAudio : MonoBehaviour
{
private static AmbientAudio instance;
private AudioSource audioSource;
[SerializeField]
private List<AudioClip> drinkSounds = new List<AudioClip>();
[SerializeField]
private List<AudioClip> eatSounds = new List<AudioClip>();
[SerializeField]
private List<AudioClip> coinSounds = new List<AudioClip>();
[SerializeField]
private List<AudioClip> maleThinkingSounds = new List<AudioClip>();
[SerializeField]
private List<AudioClip> femaleThinkingSounds = new List<AudioClip>();
private System.Random random;
private void Awake()
{
instance = this;
random = new System.Random();
}
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
public static void PlayAudioClip(AudioClip audioClip)
{
if (instance && audioClip && instance.audioSource)
{
instance.audioSource.PlayOneShot(audioClip);
}
}
public static void PlayAudioClipWithInterrupt(AudioClip audioClip)
{
StopAudio();
PlayAudioClip(audioClip);
}
public static void StopAudio()
{
if (instance.audioSource.isPlaying) instance.audioSource.Stop();
}
public static void PlayDrinkSound()
{
if (instance) instance.PlaySoundFromList(instance.drinkSounds);
}
public static void PlayEatSound()
{
if (instance) instance.PlaySoundFromList(instance.eatSounds);
}
public static void PlayCoinSound()
{
if (instance) instance.PlaySoundFromList(instance.coinSounds);
}
public static void PlayThinkingSound()
{
if (instance)
{
if (GlobalControl.instance.isMale) instance.PlaySoundFromList(instance.maleThinkingSounds);
else instance.PlaySoundFromList(instance.femaleThinkingSounds);
}
}
private void PlaySoundFromList(List<AudioClip> audioClips)
{
if (audioClips.Count == 0) return;
var index = random.Next(audioClips.Count);
PlayAudioClip(audioClips[index]);
}
}