com.tunnelsnakes.audiosystem 2.0.2 → 2.0.3

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
  }
@@ -102,7 +102,8 @@ public class AudioPresenter : MonoBehaviour {
102
102
 
103
103
  private IEnumerator WaitForEnd() {
104
104
  var time = new WaitForFixedUpdate();
105
- while (_audioSource.isPlaying) {
105
+ while (_audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples))) { //Ended or stopped, not paused
106
+
106
107
  yield return time;
107
108
  }
108
109
  Stop();
@@ -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
- AudioPresenter presenter = GetPresenter();
39
- 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
+ }
40
45
  }
41
46
 
42
47
  protected AudioPresenter GetPresenter() {
packages/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.tunnelsnakes.audiosystem",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "displayName": "TS AudioSystem",
5
5
  "description": "Audio and vibrations",
6
6
  "license": "proprietary",