com.tunnelsnakes.audiosystem 2.0.5 → 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
  }
@@ -9,7 +9,7 @@ public class AudioPresenter : MonoBehaviour {
9
9
  private Vibration _vibration;
10
10
  private Observable<bool> _isAudioEnable;
11
11
  private Observable<float> _audioGlobalVolume;
12
-
12
+
13
13
  public AudioSource AudioSource => _audioSource;
14
14
  public bool IsPlaying => _audioSource.isPlaying;
15
15
  public float Volume { get; set; }
@@ -53,24 +53,24 @@ public class AudioPresenter : MonoBehaviour {
53
53
  }
54
54
  _audioGlobalVolume = volume;
55
55
  _audioGlobalVolume.AddSubscriberAndInvoke(UpdateVolume);
56
- }
57
-
58
- #region Actions
59
-
56
+ }
57
+
58
+ #region Actions
59
+
60
60
  public void Play(float delay) {
61
61
  StartCoroutine(DelayedAction(Play, delay));
62
62
  }
63
63
 
64
64
  public void Stop(float delay) {
65
65
  StartCoroutine(DelayedAction(Stop, delay));
66
- }
67
-
66
+ }
67
+
68
68
  public void Pause(float delay) {
69
- StartCoroutine(DelayedAction(Pause, delay));
70
- }
71
-
69
+ StartCoroutine(DelayedAction(Pause, delay));
70
+ }
71
+
72
72
  public void UnPause(float delay) {
73
- StartCoroutine(DelayedAction(UnPause, delay));
73
+ StartCoroutine(DelayedAction(UnPause, delay));
74
74
  }
75
75
 
76
76
  public void Play() {
@@ -83,33 +83,33 @@ public class AudioPresenter : MonoBehaviour {
83
83
  _audioSource.Stop();
84
84
  StopAllCoroutines();
85
85
  AudioManager.SaveAudioPresenter(this);
86
- }
87
-
88
- public void Pause() {
89
- _audioSource.Pause();
90
- }
91
-
92
- public void UnPause() {
93
- _audioSource.UnPause();
86
+ }
87
+
88
+ public void Pause() {
89
+ _audioSource.Pause();
90
+ }
91
+
92
+ public void UnPause() {
93
+ _audioSource.UnPause();
94
94
  }
95
95
 
96
96
  private IEnumerator DelayedAction(Action action, float time) {
97
97
  yield return new WaitForSeconds(time);
98
98
  action?.Invoke();
99
- }
100
-
99
+ }
100
+
101
101
  #endregion
102
-
102
+
103
103
  private IEnumerator WaitForEnd() {
104
104
  var time = new WaitForFixedUpdate();
105
105
  //while (_audioSource.isPlaying || ((_audioSource.timeSamples != 0) && (_audioSource.timeSamples != _audioSource.clip.samples))) { //Ended or stopped, not paused
106
106
  // 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;
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;
113
113
  } while (isPlaying || isPlayingInPrevFrame);
114
114
  Stop();
115
115
  }
@@ -119,7 +119,6 @@ public class AudioPresenter : MonoBehaviour {
119
119
  }
120
120
 
121
121
  private void UpdateVolume(Observable<float> observable, float oldVolume, float newVolume) {
122
- _audioGlobalVolume = newVolume;
123
122
  UpdateVolume();
124
123
  }
125
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
 
packages/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.tunnelsnakes.audiosystem",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "displayName": "TS AudioSystem",
5
5
  "description": "Audio and vibrations",
6
6
  "license": "proprietary",