com.puzzlescapegames.services 1.1.4 → 1.1.5

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.
@@ -1,3 +1,4 @@
1
+ using DG.Tweening;
1
2
  using UnityEngine;
2
3
  using UnityEngine.Audio;
3
4
 
@@ -13,6 +14,7 @@ namespace PuzzlescapeGames.Services.AudioService
13
14
  private const string MUSIC = "Music";
14
15
 
15
16
  private AudioSource _musicSource;
17
+ private Tween _musicFade;
16
18
 
17
19
  private readonly AudioSourceFactory _audioFactory;
18
20
  private readonly AudioMixer _audioMixer;
@@ -28,6 +30,27 @@ namespace PuzzlescapeGames.Services.AudioService
28
30
  CreateMusic().PlayLoop( clip );
29
31
  }
30
32
 
33
+ public void ChangedMusic( AudioClip clip, float fadeOut = 0.33f, float fadeIn = 0.33f )
34
+ {
35
+ if ( _musicSource == null )
36
+ {
37
+ PlayMusic( clip );
38
+ }
39
+ else
40
+ {
41
+ _musicFade?.Kill();
42
+ _musicFade = _musicSource
43
+ .DoVolume( 0f, fadeOut )
44
+ .OnComplete( VolumeCompleted );
45
+ }
46
+
47
+ void VolumeCompleted()
48
+ {
49
+ PlayMusic( clip );
50
+ _musicFade = _musicSource.DoVolume( 1f, fadeIn );
51
+ }
52
+ }
53
+
31
54
  public void MuteMusic( bool trigger )
32
55
  {
33
56
  CreateMusic().Mute( trigger );
@@ -38,9 +61,20 @@ namespace PuzzlescapeGames.Services.AudioService
38
61
  CreateMusic().Pause( trigger );
39
62
  }
40
63
 
41
- public void PlaySound( AudioClip clip )
64
+ public AudioSource PlaySound( AudioClip clip, bool isLoop = false )
42
65
  {
43
- CreateSound().PlayOnce( clip );
66
+ var source = CreateSound();
67
+
68
+ if ( isLoop )
69
+ {
70
+ source.PlayLoop( clip );
71
+ }
72
+ else
73
+ {
74
+ source.PlayOnce( clip );
75
+ }
76
+
77
+ return source;
44
78
  }
45
79
 
46
80
  public void SetMasterVolume( float value )
@@ -1,4 +1,5 @@
1
1
  using Cysharp.Threading.Tasks;
2
+ using DG.Tweening;
2
3
  using PuzzlescapeGames.Extensions;
3
4
  using PuzzlescapeGames.IoC;
4
5
  using UnityEngine;
@@ -6,7 +7,7 @@ using UnityEngine;
6
7
  namespace PuzzlescapeGames.Services.AudioService
7
8
  {
8
9
  [ RequireComponent(typeof(UnityEngine.AudioSource)) ]
9
- internal sealed class AudioSource : ZenjectMonoPoolable
10
+ public sealed class AudioSource : ZenjectMonoPoolable
10
11
  {
11
12
  public UnityEngine.AudioSource Source
12
13
  {
@@ -37,6 +38,7 @@ namespace PuzzlescapeGames.Services.AudioService
37
38
 
38
39
  public void PlayLoop( AudioClip clip )
39
40
  {
41
+ IsPlaying = true;
40
42
  Source.clip = clip;
41
43
  Loop( true );
42
44
  Source.Play();
@@ -52,6 +54,16 @@ namespace PuzzlescapeGames.Services.AudioService
52
54
  IsPlaying = true;
53
55
  }
54
56
 
57
+ public void Stop()
58
+ {
59
+ IsPlaying = false;
60
+ }
61
+
62
+ public Tween DoVolume( float target, float duration )
63
+ {
64
+ return DOTween.To( () => Source.volume, ( x ) => Source.volume = x, target, duration );
65
+ }
66
+
55
67
  public void Mute( bool trigger )
56
68
  {
57
69
  Source.mute = trigger;
@@ -5,7 +5,8 @@ namespace PuzzlescapeGames.Services.AudioService
5
5
  public interface IAudioService
6
6
  {
7
7
  void PlayMusic( AudioClip clip );
8
- void PlaySound( AudioClip clip );
8
+ void ChangedMusic( AudioClip clip, float fadeOut = 0.33f, float fadeIn = 0.33f );
9
+ AudioSource PlaySound( AudioClip clip, bool isLoop = false );
9
10
 
10
11
  void SetMasterVolume( float value );
11
12
  void SetMusicVolume( float value );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name" : "com.puzzlescapegames.services",
3
3
  "displayName" : "Puzzlescape Games Services",
4
- "version" : "1.1.4",
4
+ "version" : "1.1.5",
5
5
  "author" : "Puzzlescape Games",
6
6
  "description" : "Common services.",
7
7
  "repository": {