com.tunnelsnakes.audiosystem 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,9 +6,9 @@ using UnityEngine;
|
|
|
6
6
|
public static class AudioManager {
|
|
7
7
|
private static Transform _container = default;
|
|
8
8
|
private static Queue<AudioPresenter> _freePresenters = new Queue<AudioPresenter>();
|
|
9
|
-
|
|
10
|
-
public static int CreatedPresenters { get; private set; }
|
|
11
|
-
public static int FreePresenters => _freePresenters.Count;
|
|
9
|
+
|
|
10
|
+
public static int CreatedPresenters { get; private set; }
|
|
11
|
+
public static int FreePresenters => _freePresenters.Count;
|
|
12
12
|
|
|
13
13
|
public static AudioPresenter GetFreeAudioPresenter() {
|
|
14
14
|
AudioPresenter presenter;
|
|
@@ -16,7 +16,7 @@ public static class AudioManager {
|
|
|
16
16
|
if (_freePresenters.Count != 0) {
|
|
17
17
|
presenter = _freePresenters.Dequeue();
|
|
18
18
|
} else {
|
|
19
|
-
presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
|
|
19
|
+
presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
|
|
20
20
|
CreatedPresenters++;
|
|
21
21
|
}
|
|
22
22
|
} while (presenter == null);
|
|
@@ -32,7 +32,7 @@ public static class AudioManager {
|
|
|
32
32
|
while (_freePresenters.Count != 0) {
|
|
33
33
|
AudioPresenter presenter = _freePresenters.Dequeue();
|
|
34
34
|
if (presenter != null) {
|
|
35
|
-
MonoBehaviour.Destroy(presenter.AudioSource);
|
|
35
|
+
MonoBehaviour.Destroy(presenter.AudioSource);
|
|
36
36
|
MonoBehaviour.Destroy(presenter);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections;
|
|
3
3
|
using System.Collections.Generic;
|
|
4
|
-
using UnityEditorInternal;
|
|
5
4
|
using UnityEngine;
|
|
6
5
|
|
|
7
6
|
[ExecuteAlways]
|
|
@@ -10,7 +9,7 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
10
9
|
private Vibration _vibration;
|
|
11
10
|
private Observable<bool> _isAudioEnable;
|
|
12
11
|
private Observable<float> _audioGlobalVolume;
|
|
13
|
-
|
|
12
|
+
|
|
14
13
|
public AudioSource AudioSource => _audioSource;
|
|
15
14
|
public bool IsPlaying => _audioSource.isPlaying;
|
|
16
15
|
public float Volume { get; set; }
|
|
@@ -54,24 +53,24 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
54
53
|
}
|
|
55
54
|
_audioGlobalVolume = volume;
|
|
56
55
|
_audioGlobalVolume.AddSubscriberAndInvoke(UpdateVolume);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
#region Actions
|
|
60
|
-
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#region Actions
|
|
59
|
+
|
|
61
60
|
public void Play(float delay) {
|
|
62
61
|
StartCoroutine(DelayedAction(Play, delay));
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
public void Stop(float delay) {
|
|
66
65
|
StartCoroutine(DelayedAction(Stop, delay));
|
|
67
|
-
}
|
|
68
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
69
68
|
public void Pause(float delay) {
|
|
70
|
-
StartCoroutine(DelayedAction(Pause, delay));
|
|
71
|
-
}
|
|
72
|
-
|
|
69
|
+
StartCoroutine(DelayedAction(Pause, delay));
|
|
70
|
+
}
|
|
71
|
+
|
|
73
72
|
public void UnPause(float delay) {
|
|
74
|
-
StartCoroutine(DelayedAction(UnPause, delay));
|
|
73
|
+
StartCoroutine(DelayedAction(UnPause, delay));
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
public void Play() {
|
|
@@ -84,33 +83,33 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
84
83
|
_audioSource.Stop();
|
|
85
84
|
StopAllCoroutines();
|
|
86
85
|
AudioManager.SaveAudioPresenter(this);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public void Pause() {
|
|
90
|
-
_audioSource.Pause();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public void UnPause() {
|
|
94
|
-
_audioSource.UnPause();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void Pause() {
|
|
89
|
+
_audioSource.Pause();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public void UnPause() {
|
|
93
|
+
_audioSource.UnPause();
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
private IEnumerator DelayedAction(Action action, float time) {
|
|
98
97
|
yield return new WaitForSeconds(time);
|
|
99
98
|
action?.Invoke();
|
|
100
|
-
}
|
|
101
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
102
101
|
#endregion
|
|
103
|
-
|
|
102
|
+
|
|
104
103
|
private IEnumerator WaitForEnd() {
|
|
105
104
|
var time = new WaitForFixedUpdate();
|
|
106
105
|
//while (_audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples))) { //Ended or stopped, not paused
|
|
107
106
|
// yield return time;
|
|
108
|
-
//}
|
|
109
|
-
bool isPlayingInPrevFrame, isPlaying = false;
|
|
110
|
-
do {
|
|
111
|
-
isPlayingInPrevFrame = isPlaying;
|
|
112
|
-
isPlaying = _audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples));
|
|
113
|
-
yield return time;
|
|
107
|
+
//}
|
|
108
|
+
bool isPlayingInPrevFrame, isPlaying = false;
|
|
109
|
+
do {
|
|
110
|
+
isPlayingInPrevFrame = isPlaying;
|
|
111
|
+
isPlaying = _audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples));
|
|
112
|
+
yield return time;
|
|
114
113
|
} while (isPlaying || isPlayingInPrevFrame);
|
|
115
114
|
Stop();
|
|
116
115
|
}
|
|
@@ -120,7 +119,6 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
private void UpdateVolume(Observable<float> observable, float oldVolume, float newVolume) {
|
|
123
|
-
_audioGlobalVolume = newVolume;
|
|
124
122
|
UpdateVolume();
|
|
125
123
|
}
|
|
126
124
|
|
|
@@ -25,8 +25,8 @@ public class Sound : ScriptableObject {
|
|
|
25
25
|
presenter.Play();
|
|
26
26
|
|
|
27
27
|
return presenter;
|
|
28
|
-
}
|
|
29
|
-
|
|
28
|
+
}
|
|
29
|
+
|
|
30
30
|
/// <summary>
|
|
31
31
|
/// Mostly for Unity events
|
|
32
32
|
/// </summary>
|
|
@@ -34,13 +34,13 @@ public class Sound : ScriptableObject {
|
|
|
34
34
|
#if UNITY_EDITOR && ODIN_INSPECTOR
|
|
35
35
|
[Sirenix.OdinInspector.Button]
|
|
36
36
|
#endif
|
|
37
|
-
public void SimplePlay() {
|
|
38
|
-
if (Application.isPlaying) {
|
|
39
|
-
Play();
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
AudioPresenter presenter = GetPresenter();
|
|
43
|
-
presenter.AudioSource.PlayOneShot(_audioClip);
|
|
37
|
+
public void SimplePlay() {
|
|
38
|
+
if (Application.isPlaying) {
|
|
39
|
+
Play();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
AudioPresenter presenter = GetPresenter();
|
|
43
|
+
presenter.AudioSource.PlayOneShot(_audioClip);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|