blob: 8a3970550131fc62a697114e73b2b6550bb68cdb (
plain)
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
|
using System.Collections;
using UnityEngine;
public class MusicManager : MonoBehaviour
{
public static MusicManager instance;
[SerializeField]
private AudioSource[] hard;
[SerializeField]
private AudioSource[] soft;
[SerializeField]
private int currentSorceIndex;
[SerializeField]
private int currentSong;
private float currentSongLoopDuration;
[SerializeField]
private AudioClip[] hardTracks;
[SerializeField]
private AudioClip[] softTracks;
[SerializeField]
private int[] BPMin;
[SerializeField]
private int[] BPMeasure;
[SerializeField]
private int[] measures;
private int intensity = 1;
private void Awake()
{
instance = this;
}
private void Start()
{
PlaySong(0, action: false);
}
private void Update()
{
if (hard[currentSorceIndex].time >= currentSongLoopDuration)
{
int num = (currentSorceIndex + 1) % 2;
hard[num].Stop();
soft[num].Stop();
hard[num].Play();
soft[num].Play();
currentSorceIndex = num;
}
int num2 = (currentSorceIndex + 1) % 2;
if (hard[num2].time >= hard[num2].clip.length - 0.1f)
{
hard[num2].Stop();
soft[num2].Stop();
}
}
public void SetIntensity(bool action)
{
int num = (action ? 1 : 0);
if (num != intensity)
{
intensity = num;
StartCoroutine(CrossFade(intensity));
}
}
public void UpdateVolume(float newVolume)
{
hard[0].volume = newVolume * (float)intensity;
hard[1].volume = newVolume * (float)intensity;
soft[0].volume = newVolume * (float)(1 - intensity);
soft[1].volume = newVolume * (float)(1 - intensity);
}
public void PlaySong(int songNumber, bool action)
{
StopAllCoroutines();
hard[0].Stop();
hard[1].Stop();
soft[0].Stop();
soft[1].Stop();
currentSong = songNumber;
currentSongLoopDuration = (float)(60 * measures[currentSong] * BPMeasure[currentSong]) / (float)BPMin[currentSong];
hard[0].clip = hardTracks[currentSong];
hard[1].clip = hardTracks[currentSong];
soft[0].clip = softTracks[currentSong];
soft[1].clip = softTracks[currentSong];
intensity = (action ? 1 : 0);
float num = OptionsMenu.instance.masterVolume * OptionsMenu.instance.musicVolume;
hard[0].volume = (float)intensity * num;
hard[1].volume = (float)intensity * num;
soft[0].volume = (float)(1 - intensity) * num;
soft[1].volume = (float)(1 - intensity) * num;
currentSorceIndex = 0;
hard[0].Play();
soft[0].Play();
}
private IEnumerator CrossFade(int newIntensity)
{
float startIntensity = ((newIntensity != 1) ? 1 : 0);
float vMod = OptionsMenu.instance.masterVolume * OptionsMenu.instance.musicVolume;
float fadeTime = 2f;
int saftyCount = 0;
for (float f = startIntensity; f != (startIntensity + 1f) % 2f; f = Mathf.Clamp(f + Time.unscaledDeltaTime * ((float)newIntensity - startIntensity) / fadeTime, 0f, 1f))
{
hard[0].volume = f * vMod;
hard[1].volume = f * vMod;
soft[0].volume = (1f - f) * vMod;
soft[1].volume = (1f - f) * vMod;
yield return null;
saftyCount++;
if ((float)saftyCount > 1000f * fadeTime)
{
Debug.LogError("Possible infinite loop");
break;
}
}
hard[0].volume = (float)newIntensity * vMod;
hard[1].volume = (float)newIntensity * vMod;
soft[0].volume = (float)(1 - newIntensity) * vMod;
soft[1].volume = (float)(1 - newIntensity) * vMod;
}
public void FadeOut(float t)
{
StartCoroutine(FadeOutCo(t));
}
private IEnumerator FadeOutCo(float fadeTime)
{
float vMod = OptionsMenu.instance.masterVolume * OptionsMenu.instance.musicVolume;
int saftyCount = 0;
for (float f = 1f; f > 0f; f -= Time.unscaledDeltaTime / fadeTime)
{
hard[0].volume = (float)intensity * vMod * f;
hard[1].volume = (float)intensity * vMod * f;
soft[0].volume = (float)(1 - intensity) * vMod * f;
soft[1].volume = (float)(1 - intensity) * vMod * f;
yield return null;
saftyCount++;
if ((float)saftyCount > 1000f * fadeTime)
{
Debug.LogError("Possible infinite loop");
break;
}
}
hard[0].volume = 0f;
hard[1].volume = 0f;
soft[0].volume = 0f;
soft[1].volume = 0f;
}
}
|