com.soosvet_games.common_tools 1.0.7 → 1.0.8

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