com.puzzlescapegames.services 1.1.4 → 1.1.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.
|
@@ -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,30 @@ 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
|
+
_musicFade?.Kill();
|
|
36
|
+
|
|
37
|
+
if ( _musicSource == null )
|
|
38
|
+
{
|
|
39
|
+
PlayMusic( clip );
|
|
40
|
+
_musicSource.Source.volume = 0f;
|
|
41
|
+
_musicFade = _musicSource.DoVolume( 1f, fadeIn );
|
|
42
|
+
}
|
|
43
|
+
else
|
|
44
|
+
{
|
|
45
|
+
_musicFade = _musicSource
|
|
46
|
+
.DoVolume( 0f, fadeOut )
|
|
47
|
+
.OnComplete( VolumeCompleted );
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void VolumeCompleted()
|
|
51
|
+
{
|
|
52
|
+
PlayMusic( clip );
|
|
53
|
+
_musicFade = _musicSource.DoVolume( 1f, fadeIn );
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
31
57
|
public void MuteMusic( bool trigger )
|
|
32
58
|
{
|
|
33
59
|
CreateMusic().Mute( trigger );
|
|
@@ -38,9 +64,20 @@ namespace PuzzlescapeGames.Services.AudioService
|
|
|
38
64
|
CreateMusic().Pause( trigger );
|
|
39
65
|
}
|
|
40
66
|
|
|
41
|
-
public
|
|
67
|
+
public AudioSource PlaySound( AudioClip clip, bool isLoop = false )
|
|
42
68
|
{
|
|
43
|
-
CreateSound()
|
|
69
|
+
var source = CreateSound();
|
|
70
|
+
|
|
71
|
+
if ( isLoop )
|
|
72
|
+
{
|
|
73
|
+
source.PlayLoop( clip );
|
|
74
|
+
}
|
|
75
|
+
else
|
|
76
|
+
{
|
|
77
|
+
source.PlayOnce( clip );
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return source;
|
|
44
81
|
}
|
|
45
82
|
|
|
46
83
|
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
|
-
|
|
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
|
|
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 );
|