com.tunnelsnakes.audiosystem 2.0.2 → 2.0.4
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,6 +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
12
|
|
|
10
13
|
public static AudioPresenter GetFreeAudioPresenter() {
|
|
11
14
|
AudioPresenter presenter;
|
|
@@ -13,7 +16,8 @@ public static class AudioManager {
|
|
|
13
16
|
if (_freePresenters.Count != 0) {
|
|
14
17
|
presenter = _freePresenters.Dequeue();
|
|
15
18
|
} else {
|
|
16
|
-
presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
|
|
19
|
+
presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
|
|
20
|
+
CreatedPresenters++;
|
|
17
21
|
}
|
|
18
22
|
} while (presenter == null);
|
|
19
23
|
return presenter;
|
|
@@ -28,6 +32,7 @@ public static class AudioManager {
|
|
|
28
32
|
while (_freePresenters.Count != 0) {
|
|
29
33
|
AudioPresenter presenter = _freePresenters.Dequeue();
|
|
30
34
|
if (presenter != null) {
|
|
35
|
+
MonoBehaviour.Destroy(presenter.AudioSource);
|
|
31
36
|
MonoBehaviour.Destroy(presenter);
|
|
32
37
|
}
|
|
33
38
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections;
|
|
3
3
|
using System.Collections.Generic;
|
|
4
|
+
using UnityEditorInternal;
|
|
4
5
|
using UnityEngine;
|
|
5
6
|
|
|
6
7
|
[ExecuteAlways]
|
|
@@ -102,9 +103,15 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
102
103
|
|
|
103
104
|
private IEnumerator WaitForEnd() {
|
|
104
105
|
var time = new WaitForFixedUpdate();
|
|
105
|
-
while (_audioSource.isPlaying) {
|
|
106
|
-
|
|
107
|
-
}
|
|
106
|
+
//while (_audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples))) { //Ended or stopped, not paused
|
|
107
|
+
// 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;
|
|
114
|
+
} while (isPlaying || isPlayingInPrevFrame);
|
|
108
115
|
Stop();
|
|
109
116
|
}
|
|
110
117
|
|
|
@@ -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,9 +34,14 @@ public class Sound : ScriptableObject {
|
|
|
34
34
|
#if UNITY_EDITOR && ODIN_INSPECTOR
|
|
35
35
|
[Sirenix.OdinInspector.Button]
|
|
36
36
|
#endif
|
|
37
|
-
public void SimplePlay() {
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
public void SimplePlay() {
|
|
38
|
+
if (Application.isPlaying) {
|
|
39
|
+
Play();
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
AudioPresenter presenter = GetPresenter();
|
|
43
|
+
presenter.AudioSource.PlayOneShot(_audioClip);
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
protected AudioPresenter GetPresenter() {
|