com.tunnelsnakes.audiosystem 2.0.0 → 2.0.2

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.
packages/LICENSE.md CHANGED
@@ -1,5 +1,5 @@
1
- # License
2
-
3
- Copyright (C) 2021
4
-
5
- AudioSystem can not be copied and/or distributed without the express permission of the author(s).
1
+ # License
2
+
3
+ Copyright (C) 2021
4
+
5
+ AudioSystem can not be copied and/or distributed without the express permission of the author(s).
packages/LICENSE.md.meta CHANGED
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: 928812144b6c1a348af23ae2c10ac0a6
3
- TextScriptImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 928812144b6c1a348af23ae2c10ac0a6
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
packages/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # AudioSystem
2
-
3
- Audio and vibrations
1
+ # AudioSystem
2
+
3
+ Audio and vibrations
packages/README.md.meta CHANGED
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: cbb2a874c5783c348948a8b027238e13
3
- TextScriptImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: cbb2a874c5783c348948a8b027238e13
3
+ TextScriptImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -1,5 +1,5 @@
1
-
2
- using System.Reflection;
3
-
4
- [assembly: AssemblyTitle("com.tunnelsnakes.audiosystem.Runtime")]
5
- [assembly: AssemblyProduct("com.tunnelsnakes.audiosystem")]
1
+
2
+ using System.Reflection;
3
+
4
+ [assembly: AssemblyTitle("com.tunnelsnakes.audiosystem.Runtime")]
5
+ [assembly: AssemblyProduct("com.tunnelsnakes.audiosystem")]
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: ec4968187fae32243aa89626b8cc6822
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: ec4968187fae32243aa89626b8cc6822
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,57 +1,57 @@
1
- using System;
2
- using System.Collections;
3
- using System.Collections.Generic;
4
- using UnityEngine;
5
-
6
- public static class AudioManager {
7
- private static Transform _container = default;
8
- private static Queue<AudioPresenter> _freePresenters = new Queue<AudioPresenter>();
9
-
10
- public static AudioPresenter GetFreeAudioPresenter() {
11
- AudioPresenter presenter;
12
- do {
13
- if (_freePresenters.Count != 0) {
14
- presenter = _freePresenters.Dequeue();
15
- } else {
16
- presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
17
- }
18
- } while (presenter == null);
19
- return presenter;
20
- }
21
-
22
- public static void SaveAudioPresenter(AudioPresenter presenter) {
23
- presenter.transform.parent = GetContainer();
24
- _freePresenters.Enqueue(presenter);
25
- }
26
-
27
- public static void Dispose() {
28
- while (_freePresenters.Count != 0) {
29
- AudioPresenter presenter = _freePresenters.Dequeue();
30
- if (presenter != null) {
31
- MonoBehaviour.Destroy(presenter);
32
- }
33
- }
34
- MonoBehaviour.Destroy(_container.gameObject);
35
- }
36
-
37
- private static Transform GetContainer() {
38
- if (_container == null) {
39
- _container = CreateContainer();
40
- }
41
- return _container;
42
- }
43
-
44
- private static Transform CreateContainer() {
45
- GameObject containerObject = new GameObject("AudioContainer");
46
- #if UNITY_EDITOR
47
- if (!Application.isPlaying) {
48
- containerObject.hideFlags = HideFlags.HideAndDontSave;
49
- } else {
50
- #endif
51
- MonoBehaviour.DontDestroyOnLoad(containerObject);
52
- #if UNITY_EDITOR
53
- }
54
- #endif
55
- return containerObject.transform;
56
- }
57
- }
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using UnityEngine;
5
+
6
+ public static class AudioManager {
7
+ private static Transform _container = default;
8
+ private static Queue<AudioPresenter> _freePresenters = new Queue<AudioPresenter>();
9
+
10
+ public static AudioPresenter GetFreeAudioPresenter() {
11
+ AudioPresenter presenter;
12
+ do {
13
+ if (_freePresenters.Count != 0) {
14
+ presenter = _freePresenters.Dequeue();
15
+ } else {
16
+ presenter = GetContainer().gameObject.AddComponent<AudioPresenter>();
17
+ }
18
+ } while (presenter == null);
19
+ return presenter;
20
+ }
21
+
22
+ public static void SaveAudioPresenter(AudioPresenter presenter) {
23
+ presenter.transform.parent = GetContainer();
24
+ _freePresenters.Enqueue(presenter);
25
+ }
26
+
27
+ public static void Dispose() {
28
+ while (_freePresenters.Count != 0) {
29
+ AudioPresenter presenter = _freePresenters.Dequeue();
30
+ if (presenter != null) {
31
+ MonoBehaviour.Destroy(presenter);
32
+ }
33
+ }
34
+ MonoBehaviour.Destroy(_container.gameObject);
35
+ }
36
+
37
+ private static Transform GetContainer() {
38
+ if (_container == null) {
39
+ _container = CreateContainer();
40
+ }
41
+ return _container;
42
+ }
43
+
44
+ private static Transform CreateContainer() {
45
+ GameObject containerObject = new GameObject("AudioContainer");
46
+ #if UNITY_EDITOR
47
+ if (!Application.isPlaying) {
48
+ containerObject.hideFlags = HideFlags.HideAndDontSave;
49
+ } else {
50
+ #endif
51
+ MonoBehaviour.DontDestroyOnLoad(containerObject);
52
+ #if UNITY_EDITOR
53
+ }
54
+ #endif
55
+ return containerObject.transform;
56
+ }
57
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 9a5034b0af552e9469204df870f16270
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 9a5034b0af552e9469204df870f16270
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,103 +1,124 @@
1
- using System;
2
- using System.Collections;
3
- using System.Collections.Generic;
4
- using UnityEngine;
5
-
6
- [ExecuteAlways]
7
- public class AudioPresenter : MonoBehaviour {
8
- private AudioSource _audioSource;
9
- private Vibration _vibration;
10
- private Observable<bool> _isAudioEnable;
11
- private Observable<float> _audioGlobalVolume;
12
-
13
- public bool IsPlaying => _audioSource.isPlaying;
14
- public float Volume { get; set; }
15
- public float Pitch {
16
- get { return _audioSource.pitch; }
17
- set { _audioSource.pitch = value; }
18
- }
19
- public bool Loop {
20
- get { return _audioSource.loop; }
21
- set { _audioSource.loop = value; }
22
- }
23
-
24
- [ExecuteAlways]
25
- private void Awake() {
26
- if (_audioSource == null) {
27
- _audioSource = gameObject.AddComponent<AudioSource>();
28
- _audioSource.playOnAwake = false;
29
- }
30
- }
31
-
32
- public void SetClip(AudioClip clip) {
33
- _audioSource.clip = clip;
34
- }
35
-
36
- public void SetVibration(Vibration vibration) {
37
- _vibration = vibration;
38
-
39
- }
40
-
41
- public void SetAudioEnableVariable(Observable<bool> state) {
42
- if (_isAudioEnable != null) {
43
- _isAudioEnable.RemoveSubscriber(UpdateState);
44
- }
45
- _isAudioEnable = state;
46
- _isAudioEnable.AddSubscriberAndInvoke(UpdateState);
47
- }
48
-
49
- public void SetGlobalAudioVolumeVariable(Observable<float> volume) {
50
- if (_audioGlobalVolume != null) {
51
- _audioGlobalVolume.RemoveSubscriber(UpdateVolume);
52
- }
53
- _audioGlobalVolume = volume;
54
- _audioGlobalVolume.AddSubscriberAndInvoke(UpdateVolume);
55
- }
56
-
57
- public void Play(float delay) {
58
- StartCoroutine(DelayedAction(Play, delay));
59
- }
60
-
61
- public void Stop(float delay) {
62
- StartCoroutine(DelayedAction(Stop, delay));
63
- }
64
-
65
- public void Play() {
66
- _audioSource.Play();
67
- if (_vibration != null) _vibration.Vibrate();
68
- StartCoroutine(WaitForEnd());
69
- }
70
-
71
- public void Stop() {
72
- _audioSource.Stop();
73
- StopAllCoroutines();
74
- AudioManager.SaveAudioPresenter(this);
75
- }
76
-
77
- private IEnumerator DelayedAction(Action action, float time) {
78
- yield return new WaitForSeconds(time);
79
- action?.Invoke();
80
- }
81
-
82
- private IEnumerator WaitForEnd() {
83
- var time = new WaitForFixedUpdate();
84
- while (_audioSource.isPlaying) {
85
- yield return time;
86
- }
87
- Stop();
88
- }
89
-
90
- private void UpdateState(Observable<bool> observable, bool oldState, bool newState) {
91
- UpdateVolume();
92
- }
93
-
94
- private void UpdateVolume(Observable<float> observable, float oldVolume, float newVolume) {
95
- _audioGlobalVolume = newVolume;
96
- UpdateVolume();
97
- }
98
-
99
- private void UpdateVolume() {
100
- float volume = Volume * _audioGlobalVolume.Value * ((_isAudioEnable != null && _isAudioEnable.Value) ? 1f : 0f);
101
- _audioSource.volume = Mathf.Clamp01(volume);
102
- }
103
- }
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using UnityEngine;
5
+
6
+ [ExecuteAlways]
7
+ public class AudioPresenter : MonoBehaviour {
8
+ private AudioSource _audioSource;
9
+ private Vibration _vibration;
10
+ private Observable<bool> _isAudioEnable;
11
+ private Observable<float> _audioGlobalVolume;
12
+
13
+ public AudioSource AudioSource => _audioSource;
14
+ public bool IsPlaying => _audioSource.isPlaying;
15
+ public float Volume { get; set; }
16
+ public float Pitch {
17
+ get { return _audioSource.pitch; }
18
+ set { _audioSource.pitch = value; }
19
+ }
20
+ public bool Loop {
21
+ get { return _audioSource.loop; }
22
+ set { _audioSource.loop = value; }
23
+ }
24
+
25
+ [ExecuteAlways]
26
+ private void Awake() {
27
+ if (_audioSource == null) {
28
+ _audioSource = gameObject.AddComponent<AudioSource>();
29
+ _audioSource.playOnAwake = false;
30
+ }
31
+ }
32
+
33
+ public void SetClip(AudioClip clip) {
34
+ _audioSource.clip = clip;
35
+ }
36
+
37
+ public void SetVibration(Vibration vibration) {
38
+ _vibration = vibration;
39
+
40
+ }
41
+
42
+ public void SetAudioEnableVariable(Observable<bool> state) {
43
+ if (_isAudioEnable != null) {
44
+ _isAudioEnable.RemoveSubscriber(UpdateState);
45
+ }
46
+ _isAudioEnable = state;
47
+ _isAudioEnable.AddSubscriberAndInvoke(UpdateState);
48
+ }
49
+
50
+ public void SetGlobalAudioVolumeVariable(Observable<float> volume) {
51
+ if (_audioGlobalVolume != null) {
52
+ _audioGlobalVolume.RemoveSubscriber(UpdateVolume);
53
+ }
54
+ _audioGlobalVolume = volume;
55
+ _audioGlobalVolume.AddSubscriberAndInvoke(UpdateVolume);
56
+ }
57
+
58
+ #region Actions
59
+
60
+ public void Play(float delay) {
61
+ StartCoroutine(DelayedAction(Play, delay));
62
+ }
63
+
64
+ public void Stop(float delay) {
65
+ StartCoroutine(DelayedAction(Stop, delay));
66
+ }
67
+
68
+ public void Pause(float delay) {
69
+ StartCoroutine(DelayedAction(Pause, delay));
70
+ }
71
+
72
+ public void UnPause(float delay) {
73
+ StartCoroutine(DelayedAction(UnPause, delay));
74
+ }
75
+
76
+ public void Play() {
77
+ _audioSource.Play();
78
+ if (_vibration != null) _vibration.Vibrate();
79
+ StartCoroutine(WaitForEnd());
80
+ }
81
+
82
+ public void Stop() {
83
+ _audioSource.Stop();
84
+ StopAllCoroutines();
85
+ AudioManager.SaveAudioPresenter(this);
86
+ }
87
+
88
+ public void Pause() {
89
+ _audioSource.Pause();
90
+ }
91
+
92
+ public void UnPause() {
93
+ _audioSource.UnPause();
94
+ }
95
+
96
+ private IEnumerator DelayedAction(Action action, float time) {
97
+ yield return new WaitForSeconds(time);
98
+ action?.Invoke();
99
+ }
100
+
101
+ #endregion
102
+
103
+ private IEnumerator WaitForEnd() {
104
+ var time = new WaitForFixedUpdate();
105
+ while (_audioSource.isPlaying) {
106
+ yield return time;
107
+ }
108
+ Stop();
109
+ }
110
+
111
+ private void UpdateState(Observable<bool> observable, bool oldState, bool newState) {
112
+ UpdateVolume();
113
+ }
114
+
115
+ private void UpdateVolume(Observable<float> observable, float oldVolume, float newVolume) {
116
+ _audioGlobalVolume = newVolume;
117
+ UpdateVolume();
118
+ }
119
+
120
+ private void UpdateVolume() {
121
+ float volume = Volume * _audioGlobalVolume.Value * ((_isAudioEnable != null && _isAudioEnable.Value) ? 1f : 0f);
122
+ _audioSource.volume = Mathf.Clamp01(volume);
123
+ }
124
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 94b4a8b8e069b55498952baedd9be50f
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 100
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 94b4a8b8e069b55498952baedd9be50f
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 100
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,53 +1,54 @@
1
- using System.Collections;
2
- using System.Collections.Generic;
3
- using UnityEngine;
4
-
5
-
6
- [CreateAssetMenu(fileName = nameof(Sound), menuName = MENU_FOLDER + nameof(Sound))]
7
- public class Sound : ScriptableObject {
8
- protected const string MENU_FOLDER = "Audio/";
9
-
10
- [SerializeField] private AudioClip _audioClip = default;
11
- [SerializeField] private Vibration _vibration = default;
12
- [Range(0f, 2f)]
13
- [SerializeField] private float _volume = 1f;
14
- [Range(0f, 2f)]
15
- [SerializeField] private float _pitch = 1f;
16
- [Range(0f, 1f)]
17
- [SerializeField] private float _pitchRange = 0f;
18
- [SerializeField] private bool _loop = false;
19
-
20
- protected virtual Observable<bool> IsAudioEnabled => GameData.Instance.AudioSettings.SoundsEnabled;
21
- protected virtual Observable<float> GlobalVolume => GameData.Instance.AudioSettings.SoundsVolume;
22
-
23
- public virtual AudioPresenter Play() {
1
+ using System.Collections;
2
+ using System.Collections.Generic;
3
+ using UnityEngine;
4
+
5
+
6
+ [CreateAssetMenu(fileName = nameof(Sound), menuName = MENU_FOLDER + nameof(Sound))]
7
+ public class Sound : ScriptableObject {
8
+ protected const string MENU_FOLDER = "Audio/";
9
+
10
+ [SerializeField] private AudioClip _audioClip = default;
11
+ [SerializeField] private Vibration _vibration = default;
12
+ [Range(0f, 2f)]
13
+ [SerializeField] private float _volume = 1f;
14
+ [Range(0f, 2f)]
15
+ [SerializeField] private float _pitch = 1f;
16
+ [Range(0f, 1f)]
17
+ [SerializeField] private float _pitchRange = 0f;
18
+ [SerializeField] private bool _loop = false;
19
+
20
+ protected virtual Observable<bool> IsAudioEnabled => GameData.Instance.AudioSettings.SoundsEnabled;
21
+ protected virtual Observable<float> GlobalVolume => GameData.Instance.AudioSettings.SoundsVolume;
22
+
23
+ public virtual AudioPresenter Play() {
24
+ AudioPresenter presenter = GetPresenter();
25
+ presenter.Play();
26
+
27
+ return presenter;
28
+ }
29
+
30
+ /// <summary>
31
+ /// Mostly for Unity events
32
+ /// </summary>
33
+ ///
34
+ #if UNITY_EDITOR && ODIN_INSPECTOR
35
+ [Sirenix.OdinInspector.Button]
36
+ #endif
37
+ public void SimplePlay() {
24
38
  AudioPresenter presenter = GetPresenter();
25
- presenter.Play();
26
-
27
- return presenter;
28
- }
29
-
30
- /// <summary>
31
- /// Mostly for Unity events
32
- /// </summary>
33
- ///
34
- #if UNITY_EDITOR && ODIN_INSPECTOR
35
- [Sirenix.OdinInspector.Button]
36
- #endif
37
- public void SimplePlay() {
38
- Play();
39
- }
40
-
41
- protected AudioPresenter GetPresenter() {
42
- AudioPresenter presenter = AudioManager.GetFreeAudioPresenter();
43
- presenter.SetClip(_audioClip);
44
- presenter.SetVibration(_vibration);
45
- presenter.Volume = _volume;
46
- presenter.Pitch = _pitch + _pitchRange * Random.Range(-1f, 1f);
47
- presenter.Loop = _loop;
48
-
49
- presenter.SetGlobalAudioVolumeVariable(GlobalVolume);
50
- presenter.SetAudioEnableVariable(IsAudioEnabled);
51
- return presenter;
52
- }
53
- }
39
+ presenter.AudioSource.PlayOneShot(_audioClip);
40
+ }
41
+
42
+ protected AudioPresenter GetPresenter() {
43
+ AudioPresenter presenter = AudioManager.GetFreeAudioPresenter();
44
+ presenter.SetClip(_audioClip);
45
+ presenter.SetVibration(_vibration);
46
+ presenter.Volume = _volume;
47
+ presenter.Pitch = _pitch + _pitchRange * Random.Range(-1f, 1f);
48
+ presenter.Loop = _loop;
49
+
50
+ presenter.SetGlobalAudioVolumeVariable(GlobalVolume);
51
+ presenter.SetAudioEnableVariable(IsAudioEnabled);
52
+ return presenter;
53
+ }
54
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 0107a3eef9bc2b24b861bfa042a800d2
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 0107a3eef9bc2b24b861bfa042a800d2
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,60 +1,60 @@
1
- using System;
2
- using System.Collections;
3
- using System.Collections.Generic;
4
- using UnityEngine;
5
-
6
- [CreateAssetMenu(fileName = nameof(StackableSound), menuName = MENU_FOLDER + nameof(StackableSound))]
7
- public class StackableSound : Sound {
8
- [Space]
9
- [SerializeField] private int _maxStackSize = 4;
10
- [SerializeField] private float _timeStep = 0.25f;
11
- [Space]
12
- [SerializeField] private bool _stackablePitch = false;
13
- [SerializeField] private float _pitchStep = 0.1f;
14
- [SerializeField] private float _pitchStackInterval = 1f;
15
-
16
- [NonSerialized]
17
- private float _lastSoundTime;
18
- [NonSerialized]
19
- private float _currentExtraPitch;
20
-
21
- public override AudioPresenter Play() {
22
- AudioPresenter presenter = null;
23
- int stackSize = GetCurrentStackSize();
24
- if (stackSize < _maxStackSize) {
25
- presenter = GetPresenter();
26
- if (_stackablePitch) {
27
- if (Time.time - _lastSoundTime <= _pitchStackInterval) {
28
- _currentExtraPitch += _pitchStep;
29
- presenter.Pitch += _currentExtraPitch;
30
- } else {
31
- _currentExtraPitch = 0f;
32
- }
33
- }
34
-
35
- if (stackSize < 0) {
36
- _lastSoundTime = Time.time;
37
- presenter.Play();
38
- } else {
39
- _lastSoundTime += _timeStep;
40
- presenter.Play(_lastSoundTime - Time.time);
41
- }
42
- }
43
-
44
- return presenter;
45
- }
46
-
47
- #if UNITY_EDITOR && ODIN_INSPECTOR
48
- [Sirenix.OdinInspector.Button]
49
- #endif
50
- public void Reset() {
51
- _lastSoundTime = 0f;
52
- _currentExtraPitch = 0f;
53
- }
54
-
55
- private int GetCurrentStackSize() {
56
- float timeDelta = _lastSoundTime - Time.time;
57
- int size = (timeDelta < 0f ? -1 : 1) * Mathf.FloorToInt(Mathf.Abs(timeDelta / _timeStep));
58
- return size;
59
- }
60
- }
1
+ using System;
2
+ using System.Collections;
3
+ using System.Collections.Generic;
4
+ using UnityEngine;
5
+
6
+ [CreateAssetMenu(fileName = nameof(StackableSound), menuName = MENU_FOLDER + nameof(StackableSound))]
7
+ public class StackableSound : Sound {
8
+ [Space]
9
+ [SerializeField] private int _maxStackSize = 4;
10
+ [SerializeField] private float _timeStep = 0.25f;
11
+ [Space]
12
+ [SerializeField] private bool _stackablePitch = false;
13
+ [SerializeField] private float _pitchStep = 0.1f;
14
+ [SerializeField] private float _pitchStackInterval = 1f;
15
+
16
+ [NonSerialized]
17
+ private float _lastSoundTime;
18
+ [NonSerialized]
19
+ private float _currentExtraPitch;
20
+
21
+ public override AudioPresenter Play() {
22
+ AudioPresenter presenter = null;
23
+ int stackSize = GetCurrentStackSize();
24
+ if (stackSize < _maxStackSize) {
25
+ presenter = GetPresenter();
26
+ if (_stackablePitch) {
27
+ if (Time.time - _lastSoundTime <= _pitchStackInterval) {
28
+ _currentExtraPitch += _pitchStep;
29
+ presenter.Pitch += _currentExtraPitch;
30
+ } else {
31
+ _currentExtraPitch = 0f;
32
+ }
33
+ }
34
+
35
+ if (stackSize < 0) {
36
+ _lastSoundTime = Time.time;
37
+ presenter.Play();
38
+ } else {
39
+ _lastSoundTime += _timeStep;
40
+ presenter.Play(_lastSoundTime - Time.time);
41
+ }
42
+ }
43
+
44
+ return presenter;
45
+ }
46
+
47
+ #if UNITY_EDITOR && ODIN_INSPECTOR
48
+ [Sirenix.OdinInspector.Button]
49
+ #endif
50
+ public void Reset() {
51
+ _lastSoundTime = 0f;
52
+ _currentExtraPitch = 0f;
53
+ }
54
+
55
+ private int GetCurrentStackSize() {
56
+ float timeDelta = _lastSoundTime - Time.time;
57
+ int size = (timeDelta < 0f ? -1 : 1) * Mathf.FloorToInt(Mathf.Abs(timeDelta / _timeStep));
58
+ return size;
59
+ }
60
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: e778783923c023244a1e2c8623fc6dd8
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: e778783923c023244a1e2c8623fc6dd8
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,8 +1,8 @@
1
- fileFormatVersion: 2
2
- guid: 5e1e3d5c1e292644e8480c6cde7e117d
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 5e1e3d5c1e292644e8480c6cde7e117d
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -1,34 +1,34 @@
1
- //#undef MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
2
- //#define MOREMOUNTAINS_NICEVIBRATIONS
3
- using System.Collections;
4
- using System.Collections.Generic;
5
- using UnityEngine;
6
- #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
7
- using Lofelt.NiceVibrations;
8
- #elif MOREMOUNTAINS_NICEVIBRATIONS
9
- using MoreMountains.NiceVibrations;
10
- #endif
11
-
12
- [CreateAssetMenu(fileName = nameof(HapticPresetVibration), menuName = MENU_FOLDER + nameof(HapticPresetVibration))]
13
- public class HapticPresetVibration : Vibration {
14
-
15
- #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
16
- [SerializeField] private HapticPatterns.PresetType _type = HapticPatterns.PresetType.None;
17
- #elif MOREMOUNTAINS_NICEVIBRATIONS
18
- [SerializeField] private HapticTypes _type = HapticTypes.None;
19
- #endif
20
-
21
- public override void Vibrate() {
22
- if (CanVibrate) {
23
- #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
24
- HapticPatterns.PlayPreset(_type);
25
- #elif MOREMOUNTAINS_NICEVIBRATIONS
26
- MMVibrationManager.Haptic(_type, false, true, null);
27
- #else
28
- #if UNITY_EDITOR
29
- Debug.LogWarning("Vibrations are disabled!");
30
- #endif
31
- #endif
32
- }
33
- }
34
- }
1
+ //#undef MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
2
+ //#define MOREMOUNTAINS_NICEVIBRATIONS
3
+ using System.Collections;
4
+ using System.Collections.Generic;
5
+ using UnityEngine;
6
+ #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
7
+ using Lofelt.NiceVibrations;
8
+ #elif MOREMOUNTAINS_NICEVIBRATIONS
9
+ using MoreMountains.NiceVibrations;
10
+ #endif
11
+
12
+ [CreateAssetMenu(fileName = nameof(HapticPresetVibration), menuName = MENU_FOLDER + nameof(HapticPresetVibration))]
13
+ public class HapticPresetVibration : Vibration {
14
+
15
+ #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
16
+ [SerializeField] private HapticPatterns.PresetType _type = HapticPatterns.PresetType.None;
17
+ #elif MOREMOUNTAINS_NICEVIBRATIONS
18
+ [SerializeField] private HapticTypes _type = HapticTypes.None;
19
+ #endif
20
+
21
+ public override void Vibrate() {
22
+ if (CanVibrate) {
23
+ #if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
24
+ HapticPatterns.PlayPreset(_type);
25
+ #elif MOREMOUNTAINS_NICEVIBRATIONS
26
+ MMVibrationManager.Haptic(_type, false, true, null);
27
+ #else
28
+ #if UNITY_EDITOR
29
+ Debug.LogWarning("Vibrations are disabled!");
30
+ #endif
31
+ #endif
32
+ }
33
+ }
34
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 5019a6c27cca1eb48ba8811fd611d43b
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 5019a6c27cca1eb48ba8811fd611d43b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,10 +1,10 @@
1
- using System.Collections;
2
- using System.Collections.Generic;
3
- using UnityEngine;
4
-
5
- public abstract class Vibration : ScriptableObject {
6
- protected const string MENU_FOLDER = "Vibration/";
7
- protected bool CanVibrate => GameData.Instance.AudioSettings.VibrationsEnabled.Value;
8
-
9
- public abstract void Vibrate();
10
- }
1
+ using System.Collections;
2
+ using System.Collections.Generic;
3
+ using UnityEngine;
4
+
5
+ public abstract class Vibration : ScriptableObject {
6
+ protected const string MENU_FOLDER = "Vibration/";
7
+ protected bool CanVibrate => GameData.Instance.AudioSettings.VibrationsEnabled.Value;
8
+
9
+ public abstract void Vibrate();
10
+ }
@@ -1,11 +1,11 @@
1
- fileFormatVersion: 2
2
- guid: 5cc157c4ad634fa40bae7d723887849e
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 5cc157c4ad634fa40bae7d723887849e
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -1,8 +1,8 @@
1
- fileFormatVersion: 2
2
- guid: 711cecfdad3dfce49b12184eb22d1c28
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 711cecfdad3dfce49b12184eb22d1c28
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -1,8 +1,8 @@
1
- fileFormatVersion: 2
2
- guid: e20be6ade4aa3dc4295905bc49f33094
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: e20be6ade4aa3dc4295905bc49f33094
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: c1eb42fcf27eaf348a30944660a3321f
3
- AssemblyDefinitionImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: c1eb42fcf27eaf348a30944660a3321f
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
packages/Runtime.meta CHANGED
@@ -1,8 +1,8 @@
1
- fileFormatVersion: 2
2
- guid: 7d1306cddc1f2614598fa3dac7046e41
3
- folderAsset: yes
4
- DefaultImporter:
5
- externalObjects: {}
6
- userData:
7
- assetBundleName:
8
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: 7d1306cddc1f2614598fa3dac7046e41
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
packages/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.tunnelsnakes.audiosystem",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "displayName": "TS AudioSystem",
5
5
  "description": "Audio and vibrations",
6
6
  "license": "proprietary",
@@ -1,7 +1,7 @@
1
- fileFormatVersion: 2
2
- guid: f95dc0157bd93de44ad78bea29f088d0
3
- PackageManifestImporter:
4
- externalObjects: {}
5
- userData:
6
- assetBundleName:
7
- assetBundleVariant:
1
+ fileFormatVersion: 2
2
+ guid: f95dc0157bd93de44ad78bea29f088d0
3
+ PackageManifestImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant: