com.soosvet_games.common_tools 1.0.6 → 1.0.7

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.
@@ -0,0 +1,146 @@
1
+ %YAML 1.1
2
+ %TAG !u! tag:unity3d.com,2011:
3
+ --- !u!244 &-8461503843806639858
4
+ AudioMixerEffectController:
5
+ m_ObjectHideFlags: 3
6
+ m_CorrespondingSourceObject: {fileID: 0}
7
+ m_PrefabInstance: {fileID: 0}
8
+ m_PrefabAsset: {fileID: 0}
9
+ m_Name:
10
+ m_EffectID: c24b38b14a201af4a8bb8cc381f855d8
11
+ m_EffectName: Attenuation
12
+ m_MixLevel: 2a05e862ec030764a817f269040402a8
13
+ m_Parameters: []
14
+ m_SendTarget: {fileID: 0}
15
+ m_EnableWetMix: 0
16
+ m_Bypass: 0
17
+ --- !u!243 &-7223703584047178425
18
+ AudioMixerGroupController:
19
+ m_ObjectHideFlags: 0
20
+ m_CorrespondingSourceObject: {fileID: 0}
21
+ m_PrefabInstance: {fileID: 0}
22
+ m_PrefabAsset: {fileID: 0}
23
+ m_Name: Music
24
+ m_AudioMixer: {fileID: 24100000}
25
+ m_GroupID: 415e865aecb0dec4989735320c5bb716
26
+ m_Children: []
27
+ m_Volume: f4cef9da461a56742a9df82963bd79e5
28
+ m_Pitch: 78c764bb0b17db645a6fca89748403f3
29
+ m_Send: 00000000000000000000000000000000
30
+ m_Effects:
31
+ - {fileID: 3972384365331816477}
32
+ m_UserColorIndex: 0
33
+ m_Mute: 0
34
+ m_Solo: 0
35
+ m_BypassEffects: 0
36
+ --- !u!241 &24100000
37
+ AudioMixerController:
38
+ m_ObjectHideFlags: 0
39
+ m_CorrespondingSourceObject: {fileID: 0}
40
+ m_PrefabInstance: {fileID: 0}
41
+ m_PrefabAsset: {fileID: 0}
42
+ m_Name: AudioMixer
43
+ m_OutputGroup: {fileID: 0}
44
+ m_MasterGroup: {fileID: 24300002}
45
+ m_Snapshots:
46
+ - {fileID: 24500006}
47
+ m_StartSnapshot: {fileID: 24500006}
48
+ m_SuspendThreshold: -80
49
+ m_EnableSuspend: 1
50
+ m_UpdateMode: 0
51
+ m_ExposedParameters:
52
+ - guid: 8be27f7d6772d324b8a32e0f5eef83b2
53
+ name: MasterVolume
54
+ - guid: f4cef9da461a56742a9df82963bd79e5
55
+ name: MusicVolume
56
+ - guid: 53532c3a048fc5f488a95c8142d94800
57
+ name: SFXVolume
58
+ m_AudioMixerGroupViews:
59
+ - guids:
60
+ - 0700f2dc9a05e7e4d90aa3186eab1b88
61
+ - 415e865aecb0dec4989735320c5bb716
62
+ - ffe1964c3c64bce47a44ed22eab1bc8c
63
+ name: View
64
+ m_CurrentViewIndex: 0
65
+ m_TargetSnapshot: {fileID: 24500006}
66
+ --- !u!243 &24300002
67
+ AudioMixerGroupController:
68
+ m_ObjectHideFlags: 0
69
+ m_CorrespondingSourceObject: {fileID: 0}
70
+ m_PrefabInstance: {fileID: 0}
71
+ m_PrefabAsset: {fileID: 0}
72
+ m_Name: Master
73
+ m_AudioMixer: {fileID: 24100000}
74
+ m_GroupID: 0700f2dc9a05e7e4d90aa3186eab1b88
75
+ m_Children:
76
+ - {fileID: -7223703584047178425}
77
+ - {fileID: 8236444753114105489}
78
+ m_Volume: 8be27f7d6772d324b8a32e0f5eef83b2
79
+ m_Pitch: 5cc0cb3aaf2e46d42b51763cf66e1246
80
+ m_Send: 00000000000000000000000000000000
81
+ m_Effects:
82
+ - {fileID: 24400004}
83
+ m_UserColorIndex: 0
84
+ m_Mute: 0
85
+ m_Solo: 0
86
+ m_BypassEffects: 0
87
+ --- !u!244 &24400004
88
+ AudioMixerEffectController:
89
+ m_ObjectHideFlags: 3
90
+ m_CorrespondingSourceObject: {fileID: 0}
91
+ m_PrefabInstance: {fileID: 0}
92
+ m_PrefabAsset: {fileID: 0}
93
+ m_Name:
94
+ m_EffectID: 8dc4092d1a1a5f849bbb99e207fe44d5
95
+ m_EffectName: Attenuation
96
+ m_MixLevel: 84dc2916f7346af4b989de3c6b0e8c51
97
+ m_Parameters: []
98
+ m_SendTarget: {fileID: 0}
99
+ m_EnableWetMix: 0
100
+ m_Bypass: 0
101
+ --- !u!245 &24500006
102
+ AudioMixerSnapshotController:
103
+ m_ObjectHideFlags: 0
104
+ m_CorrespondingSourceObject: {fileID: 0}
105
+ m_PrefabInstance: {fileID: 0}
106
+ m_PrefabAsset: {fileID: 0}
107
+ m_Name: Snapshot
108
+ m_AudioMixer: {fileID: 24100000}
109
+ m_SnapshotID: 2f7b4746b332c86469f3e5c36a0d171f
110
+ m_FloatValues:
111
+ 53532c3a048fc5f488a95c8142d94800: -0.025776558
112
+ 8be27f7d6772d324b8a32e0f5eef83b2: -0.27209902
113
+ m_TransitionOverrides: {}
114
+ --- !u!244 &3972384365331816477
115
+ AudioMixerEffectController:
116
+ m_ObjectHideFlags: 3
117
+ m_CorrespondingSourceObject: {fileID: 0}
118
+ m_PrefabInstance: {fileID: 0}
119
+ m_PrefabAsset: {fileID: 0}
120
+ m_Name:
121
+ m_EffectID: 11568c368f090bc41a8c1f78b98b9312
122
+ m_EffectName: Attenuation
123
+ m_MixLevel: 6d117e9f830c04f418b98e828995eb86
124
+ m_Parameters: []
125
+ m_SendTarget: {fileID: 0}
126
+ m_EnableWetMix: 0
127
+ m_Bypass: 0
128
+ --- !u!243 &8236444753114105489
129
+ AudioMixerGroupController:
130
+ m_ObjectHideFlags: 0
131
+ m_CorrespondingSourceObject: {fileID: 0}
132
+ m_PrefabInstance: {fileID: 0}
133
+ m_PrefabAsset: {fileID: 0}
134
+ m_Name: SFX
135
+ m_AudioMixer: {fileID: 24100000}
136
+ m_GroupID: ffe1964c3c64bce47a44ed22eab1bc8c
137
+ m_Children: []
138
+ m_Volume: 53532c3a048fc5f488a95c8142d94800
139
+ m_Pitch: eae576986e55aaa41ba4b10f9e81ff1c
140
+ m_Send: 00000000000000000000000000000000
141
+ m_Effects:
142
+ - {fileID: -8461503843806639858}
143
+ m_UserColorIndex: 0
144
+ m_Mute: 0
145
+ m_Solo: 0
146
+ m_BypassEffects: 0
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: c6cc49c36bf4f2240910895c31fe7cee
3
+ NativeFormatImporter:
4
+ externalObjects: {}
5
+ mainObjectFileID: 24100000
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 1a208ce236f78bf4db74e6780246b932
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,77 @@
1
+ using UnityEngine;
2
+ using UnityEngine.Audio;
3
+
4
+ namespace SoosvetGames.CommonTools.Services.AudioService
5
+ {
6
+ internal sealed class AudioService : IAudioService
7
+ {
8
+ private const string MIXER_MASTER = "MasterVolume";
9
+ private const string MIXER_MUSIC = "MusicVolume";
10
+ private const string MIXER_SFX = "SFXVolume";
11
+
12
+ private const string SFX = "SFX";
13
+ private const string MUSIC = "Music";
14
+
15
+ private readonly AudioSourceFactory _audioFactory;
16
+ private readonly AudioMixer _audioMixer;
17
+
18
+ public AudioService( AudioSourceFactory audioFactory, AudioMixer audioMixer )
19
+ {
20
+ _audioFactory = audioFactory;
21
+ _audioMixer = audioMixer;
22
+ }
23
+
24
+ public AudioSource PlaySound( AudioClip clip, bool isLoop = false )
25
+ {
26
+ var source = CreateSound();
27
+
28
+ if ( isLoop )
29
+ {
30
+ source.PlayLoop( clip );
31
+ }
32
+ else
33
+ {
34
+ source.PlayOnce( clip );
35
+ }
36
+
37
+ return source;
38
+ }
39
+
40
+ public void SetMixerMasterVolume( float value )
41
+ {
42
+ _audioMixer.SetFloat( MIXER_MASTER, value );
43
+ }
44
+
45
+ public void SetMixerMusicVolume( float value )
46
+ {
47
+ _audioMixer.SetFloat( MIXER_MUSIC, value );
48
+ }
49
+
50
+ public void SetMixerSoundVolume( float value )
51
+ {
52
+ _audioMixer.SetFloat( MIXER_SFX, value );
53
+ }
54
+
55
+ private AudioSource CreateSound()
56
+ {
57
+ var source = _audioFactory.Create();
58
+ if ( _audioMixer != null )
59
+ {
60
+ source.Source.outputAudioMixerGroup = _audioMixer.FindMatchingGroups( SFX )[ 0 ];
61
+ }
62
+
63
+ return source;
64
+ }
65
+
66
+ public MusicSource CreateMusic()
67
+ {
68
+ var source = _audioFactory.Create();
69
+ if ( _audioMixer != null )
70
+ {
71
+ source.Source.outputAudioMixerGroup = _audioMixer.FindMatchingGroups( MUSIC )[ 0 ];
72
+ }
73
+
74
+ return new( source );
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: a188bea943044d769e3becff1ef22e7c
3
+ timeCreated: 1786797139
@@ -0,0 +1,18 @@
1
+ using UnityEngine.Audio;
2
+ using Zenject;
3
+
4
+ namespace SoosvetGames.CommonTools.Services.AudioService
5
+ {
6
+ public sealed class AudioServiceInstaller
7
+ {
8
+ public static void Install( DiContainer container, AudioMixer audioMixer, int poolSize = 1 )
9
+ {
10
+ container.BindFactory< AudioSource, AudioSourceFactory >()
11
+ .FromMonoPoolableMemoryPool((x) => x.WithInitialSize( poolSize )
12
+ .FromNewComponentOnNewGameObject())
13
+ .WhenInjectedInto<AudioService>().Lazy();
14
+ container.BindInstance( audioMixer ).WhenInjectedInto< AudioService >().Lazy();
15
+ container.BindInterfacesTo< AudioService >().AsSingle().Lazy();
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: ee8d8d83e4b94489858dc40e3651cbd3
3
+ timeCreated: 1786798166
@@ -0,0 +1,118 @@
1
+ using Cysharp.Threading.Tasks;
2
+ using DG.Tweening;
3
+ using SoosvetGames.IoC;
4
+ using UnityEngine;
5
+
6
+ namespace SoosvetGames.CommonTools.Services.AudioService
7
+ {
8
+ [ RequireComponent( typeof(UnityEngine.AudioSource) ) ]
9
+ public sealed class AudioSource : ZenjectMonoPoolable
10
+ {
11
+ public UnityEngine.AudioSource Source
12
+ {
13
+ get
14
+ {
15
+ if ( _source == null )
16
+ {
17
+ _source = GetComponent< UnityEngine.AudioSource >();
18
+ }
19
+
20
+ return _source;
21
+ }
22
+ }
23
+ private UnityEngine.AudioSource _source;
24
+
25
+ public bool IsPlaying => Source.isPlaying || _isPaused;
26
+ public bool IsLoop => Source.loop;
27
+
28
+ private bool _isPaused;
29
+ private int _playVersion;
30
+
31
+ public void PlayLoop( AudioClip clip )
32
+ {
33
+ Prepare( clip, true );
34
+ Source.Play();
35
+ }
36
+
37
+ public void PlayOnce( AudioClip clip )
38
+ {
39
+ Prepare( clip, false );
40
+
41
+ var playVersion = ++_playVersion;
42
+
43
+ Source.Play();
44
+
45
+ WaitForComplete( playVersion ).Forget();
46
+ }
47
+
48
+ public void Stop()
49
+ {
50
+ ++_playVersion;
51
+
52
+ _isPaused = false;
53
+
54
+ Source.Stop();
55
+ Source.clip = null;
56
+
57
+ DespawnIt();
58
+ }
59
+
60
+ public void Rewind()
61
+ {
62
+ Source.time = 0f;
63
+ }
64
+
65
+ public void Pause( bool trigger )
66
+ {
67
+ _isPaused = trigger;
68
+
69
+ if ( trigger )
70
+ {
71
+ Source.Pause();
72
+ }
73
+ else
74
+ {
75
+ Source.UnPause();
76
+ }
77
+ }
78
+
79
+ public void Mute( bool trigger )
80
+ {
81
+ Source.mute = trigger;
82
+ }
83
+
84
+ public void Loop( bool trigger )
85
+ {
86
+ Source.loop = trigger;
87
+ }
88
+
89
+ public Tween DoVolume( float target, float duration )
90
+ {
91
+ return DOTween.To( () => Source.volume, x => Source.volume = x, target, duration );
92
+ }
93
+
94
+ private void Prepare( AudioClip clip, bool loop )
95
+ {
96
+ ++_playVersion;
97
+
98
+ _isPaused = false;
99
+
100
+ Source.Stop();
101
+ Source.clip = clip;
102
+ Source.loop = loop;
103
+ }
104
+
105
+ private async UniTask WaitForComplete( int playVersion )
106
+ {
107
+ await UniTask.WaitUntil( () => playVersion != _playVersion || !IsPlaying, cancellationToken: destroyCancellationToken );
108
+
109
+ if ( playVersion != _playVersion )
110
+ {
111
+ return;
112
+ }
113
+
114
+ Source.clip = null;
115
+ DespawnIt();
116
+ }
117
+ }
118
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 689165225ef24fe59c4554a08eb76f19
3
+ timeCreated: 1786797163
@@ -0,0 +1,6 @@
1
+ using Zenject;
2
+
3
+ namespace SoosvetGames.CommonTools.Services.AudioService
4
+ {
5
+ internal sealed class AudioSourceFactory : PlaceholderFactory< AudioSource > { }
6
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 5dcfad645ce24b03b4662fd7af6dce79
3
+ timeCreated: 1786797883
@@ -0,0 +1,15 @@
1
+ using UnityEngine;
2
+
3
+ namespace SoosvetGames.CommonTools.Services.AudioService
4
+ {
5
+ public interface IAudioService
6
+ {
7
+ AudioSource PlaySound( AudioClip clip, bool isLoop = false );
8
+
9
+ void SetMixerMasterVolume( float value );
10
+ void SetMixerMusicVolume( float value );
11
+ void SetMixerSoundVolume( float value );
12
+
13
+ MusicSource CreateMusic();
14
+ }
15
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 56021ea433074645a7bfce852897052d
3
+ timeCreated: 1786797937
@@ -0,0 +1,67 @@
1
+ using DG.Tweening;
2
+ using System;
3
+ using UnityEngine;
4
+
5
+ namespace SoosvetGames.CommonTools.Services.AudioService
6
+ {
7
+ public sealed class MusicSource
8
+ {
9
+ public AudioSource Audio { get; }
10
+
11
+ private Tween _fade;
12
+
13
+ public MusicSource( AudioSource audioSource )
14
+ {
15
+ Audio = audioSource ?? throw new ArgumentNullException( nameof(audioSource) );
16
+ }
17
+
18
+ public void Play( AudioClip clip )
19
+ {
20
+ Audio.PlayLoop( clip );
21
+ }
22
+
23
+ public void Change( AudioClip clip, float fadeOut = 0.33f, float fadeIn = 0.33f )
24
+ {
25
+ _fade?.Kill();
26
+
27
+ if ( _fade == null )
28
+ {
29
+ Play( clip );
30
+ Audio.Source.volume = 0f;
31
+ _fade = Audio.DoVolume( 1f, fadeIn );
32
+ }
33
+ else
34
+ {
35
+ _fade = Audio
36
+ .DoVolume( 0f, fadeOut )
37
+ .OnComplete( VolumeCompleted );
38
+ }
39
+
40
+ void VolumeCompleted()
41
+ {
42
+ Play( clip );
43
+ _fade = Audio.DoVolume( 1f, fadeIn );
44
+ }
45
+ }
46
+
47
+ public void SetVolume( float value )
48
+ {
49
+ Audio.Source.volume = value;
50
+ }
51
+
52
+ public Tween DoVolume( float target, float duration )
53
+ {
54
+ return Audio.DoVolume( target, duration );
55
+ }
56
+
57
+ public void Pause( bool trigger )
58
+ {
59
+ Audio.Pause( trigger );
60
+ }
61
+
62
+ public void Mute( bool trigger )
63
+ {
64
+ Audio.Mute( trigger );
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 55faaa2afa144884abb62ba1fbb0e6c4
3
+ timeCreated: 1786797988
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 7c3e19f7a328413fac74b59c3c249355
3
+ timeCreated: 1786797127
@@ -2,7 +2,10 @@
2
2
  "name": "SoosvetGames.CommonTools",
3
3
  "rootNamespace": "",
4
4
  "references": [
5
- "GUID:0c0c8357443d62a4c9e55fe39d3a3e51"
5
+ "GUID:0c0c8357443d62a4c9e55fe39d3a3e51",
6
+ "GUID:0d8beb7f090555447a6cf5ce9e54dbb4",
7
+ "GUID:9e5f34ba0cc07fc4184cb3bf9d5c4b7e",
8
+ "GUID:f51ebe6a0ceec4240a699833d6309b23"
6
9
  ],
7
10
  "includePlatforms": [],
8
11
  "excludePlatforms": [],
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.6",
4
+ "version" : "1.0.7",
5
5
  "author" : "Soosvet Games",
6
6
  "description" : "Common tools for Unity.",
7
7
  "repository": {