com.soosvet_games.common_tools 1.0.8 → 1.0.9

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.
@@ -22,61 +22,50 @@ namespace SoosvetGames.CommonTools.Services.AudioService
22
22
  }
23
23
  private UnityEngine.AudioSource _source;
24
24
 
25
- public bool IsPlaying
26
- {
27
- get => _isPlaying;
28
- private set
29
- {
30
- _isPlaying = value;
31
- PlayingChangedHandler();
32
- }
33
- }
34
- private bool _isPlaying = false;
35
-
36
- public bool isLoop { get; private set; } = false;
25
+ public bool IsPlaying => Source.isPlaying || _isPaused;
26
+ public bool IsLoop => Source.loop;
27
+
28
+ private bool _isPaused;
29
+ private int _playVersion;
37
30
 
38
31
  public void PlayLoop( AudioClip clip )
39
32
  {
40
- IsPlaying = true;
41
- Source.clip = clip;
42
- Loop( true );
33
+ Prepare( clip, true );
43
34
  Source.Play();
44
35
  }
45
36
 
46
37
  public void PlayOnce( AudioClip clip )
47
38
  {
48
- Loop( false );
39
+ Prepare( clip, false );
40
+
41
+ var playVersion = ++_playVersion;
49
42
 
50
- StartPlayDelay( clip.length );
51
- Source.PlayOneShot( clip );
43
+ Source.Play();
52
44
 
53
- IsPlaying = true;
45
+ WaitForComplete( playVersion ).Forget();
54
46
  }
55
47
 
56
48
  public void Stop()
57
49
  {
58
- IsPlaying = false;
59
- Source.clip = null;
60
- }
61
-
62
- public void Rewind()
63
- {
64
- Source.time = 0;
50
+ ++_playVersion;
51
+
52
+ _isPaused = false;
53
+
65
54
  Source.Stop();
66
- }
55
+ Source.clip = null;
67
56
 
68
- public Tween DoVolume( float target, float duration )
69
- {
70
- return DOTween.To( () => Source.volume, ( x ) => Source.volume = x, target, duration );
57
+ DespawnIt();
71
58
  }
72
59
 
73
- public void Mute( bool trigger )
60
+ public void Rewind()
74
61
  {
75
- Source.mute = trigger;
62
+ Source.time = 0f;
76
63
  }
77
64
 
78
65
  public void Pause( bool trigger )
79
66
  {
67
+ _isPaused = trigger;
68
+
80
69
  if ( trigger )
81
70
  {
82
71
  Source.Pause();
@@ -86,32 +75,44 @@ namespace SoosvetGames.CommonTools.Services.AudioService
86
75
  Source.UnPause();
87
76
  }
88
77
  }
89
-
78
+
79
+ public void Mute( bool trigger )
80
+ {
81
+ Source.mute = trigger;
82
+ }
83
+
90
84
  public void Loop( bool trigger )
91
85
  {
92
- isLoop = trigger;
93
86
  Source.loop = trigger;
94
87
  }
95
-
96
- private void StartPlayDelay( float playTime )
88
+
89
+ public Tween DoVolume( float target, float duration )
97
90
  {
98
- PlayDelay( playTime ).Forget();
91
+ return DOTween.To( () => Source.volume, x => Source.volume = x, target, duration );
99
92
  }
100
-
101
- private async UniTask PlayDelay( float playTime )
93
+
94
+ private void Prepare( AudioClip clip, bool loop )
102
95
  {
103
- await UniTask.WaitForSeconds( playTime, cancellationToken: destroyCancellationToken );
104
- await UniTask.WaitForSeconds( 0.16f, cancellationToken: destroyCancellationToken );
105
-
106
- IsPlaying = false;
96
+ ++_playVersion;
97
+
98
+ _isPaused = false;
99
+
100
+ Source.Stop();
101
+ Source.clip = clip;
102
+ Source.loop = loop;
107
103
  }
108
104
 
109
- private void PlayingChangedHandler()
105
+ private async UniTask WaitForComplete( int playVersion )
110
106
  {
111
- if ( !IsPlaying )
107
+ await UniTask.WaitUntil( () => playVersion != _playVersion || !IsPlaying, cancellationToken: destroyCancellationToken );
108
+
109
+ if ( playVersion != _playVersion )
112
110
  {
113
- DespawnIt();
111
+ return;
114
112
  }
113
+
114
+ Source.clip = null;
115
+ DespawnIt();
115
116
  }
116
117
  }
117
118
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name" : "com.soosvet_games.common_tools",
3
3
  "displayName" : "Soosvet Games Common Tools",
4
- "version" : "1.0.8",
4
+ "version" : "1.0.9",
5
5
  "author" : "Soosvet Games",
6
6
  "description" : "Common tools for Unity.",
7
7
  "repository": {