com.tunnelsnakes.audiosystem 1.1.2 → 2.0.0
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/Runtime/Scripts/Audio/AudioManager.cs +9 -1
- packages/Runtime/Scripts/Audio/AudioPresenter.cs +6 -2
- packages/Runtime/Scripts/Audio/Sound.cs +11 -0
- packages/Runtime/Scripts/Audio/StackableSound.cs +8 -0
- packages/Runtime/Scripts/Vibrations/HapticVibration.cs +13 -5
- packages/Runtime/com.tunnelsnakes.audiosystem.Runtime.asmdef +19 -17
- packages/package.json +1 -1
|
@@ -43,7 +43,15 @@ public static class AudioManager {
|
|
|
43
43
|
|
|
44
44
|
private static Transform CreateContainer() {
|
|
45
45
|
GameObject containerObject = new GameObject("AudioContainer");
|
|
46
|
-
|
|
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
|
|
47
55
|
return containerObject.transform;
|
|
48
56
|
}
|
|
49
57
|
}
|
|
@@ -3,6 +3,7 @@ using System.Collections;
|
|
|
3
3
|
using System.Collections.Generic;
|
|
4
4
|
using UnityEngine;
|
|
5
5
|
|
|
6
|
+
[ExecuteAlways]
|
|
6
7
|
public class AudioPresenter : MonoBehaviour {
|
|
7
8
|
private AudioSource _audioSource;
|
|
8
9
|
private Vibration _vibration;
|
|
@@ -20,9 +21,12 @@ public class AudioPresenter : MonoBehaviour {
|
|
|
20
21
|
set { _audioSource.loop = value; }
|
|
21
22
|
}
|
|
22
23
|
|
|
24
|
+
[ExecuteAlways]
|
|
23
25
|
private void Awake() {
|
|
24
|
-
_audioSource
|
|
25
|
-
|
|
26
|
+
if (_audioSource == null) {
|
|
27
|
+
_audioSource = gameObject.AddComponent<AudioSource>();
|
|
28
|
+
_audioSource.playOnAwake = false;
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
public void SetClip(AudioClip clip) {
|
|
@@ -27,6 +27,17 @@ public class Sound : ScriptableObject {
|
|
|
27
27
|
return presenter;
|
|
28
28
|
}
|
|
29
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
|
+
|
|
30
41
|
protected AudioPresenter GetPresenter() {
|
|
31
42
|
AudioPresenter presenter = AudioManager.GetFreeAudioPresenter();
|
|
32
43
|
presenter.SetClip(_audioClip);
|
|
@@ -44,6 +44,14 @@ public class StackableSound : Sound {
|
|
|
44
44
|
return presenter;
|
|
45
45
|
}
|
|
46
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
|
+
|
|
47
55
|
private int GetCurrentStackSize() {
|
|
48
56
|
float timeDelta = _lastSoundTime - Time.time;
|
|
49
57
|
int size = (timeDelta < 0f ? -1 : 1) * Mathf.FloorToInt(Mathf.Abs(timeDelta / _timeStep));
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
+
//#undef MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
|
|
2
|
+
//#define MOREMOUNTAINS_NICEVIBRATIONS
|
|
1
3
|
using System.Collections;
|
|
2
4
|
using System.Collections.Generic;
|
|
3
5
|
using UnityEngine;
|
|
4
|
-
#if
|
|
6
|
+
#if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
|
|
7
|
+
using Lofelt.NiceVibrations;
|
|
8
|
+
#elif MOREMOUNTAINS_NICEVIBRATIONS
|
|
5
9
|
using MoreMountains.NiceVibrations;
|
|
6
10
|
#endif
|
|
7
11
|
|
|
8
|
-
[CreateAssetMenu(fileName = nameof(
|
|
9
|
-
public class
|
|
12
|
+
[CreateAssetMenu(fileName = nameof(HapticPresetVibration), menuName = MENU_FOLDER + nameof(HapticPresetVibration))]
|
|
13
|
+
public class HapticPresetVibration : Vibration {
|
|
10
14
|
|
|
11
|
-
#if
|
|
15
|
+
#if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
|
|
16
|
+
[SerializeField] private HapticPatterns.PresetType _type = HapticPatterns.PresetType.None;
|
|
17
|
+
#elif MOREMOUNTAINS_NICEVIBRATIONS
|
|
12
18
|
[SerializeField] private HapticTypes _type = HapticTypes.None;
|
|
13
19
|
#endif
|
|
14
20
|
|
|
15
21
|
public override void Vibrate() {
|
|
16
22
|
if (CanVibrate) {
|
|
17
|
-
#if
|
|
23
|
+
#if MOREMOUNTAINS_NICEVIBRATIONS_INSTALLED
|
|
24
|
+
HapticPatterns.PlayPreset(_type);
|
|
25
|
+
#elif MOREMOUNTAINS_NICEVIBRATIONS
|
|
18
26
|
MMVibrationManager.Haptic(_type, false, true, null);
|
|
19
27
|
#else
|
|
20
28
|
#if UNITY_EDITOR
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "com.tunnelsnakes.audiosystem.Runtime",
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
"GUID:
|
|
6
|
-
"GUID:
|
|
7
|
-
"GUID:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
1
|
+
{
|
|
2
|
+
"name": "com.tunnelsnakes.audiosystem.Runtime",
|
|
3
|
+
"rootNamespace": "",
|
|
4
|
+
"references": [
|
|
5
|
+
"GUID:ec99747e8eb95ee488f6cfa3a8e647b9",
|
|
6
|
+
"GUID:041029188fa88c54f9efffc039b6a1c9",
|
|
7
|
+
"GUID:865b414a121ed594e91db2e09f65d38c",
|
|
8
|
+
"GUID:c5c32a628b9233446bcce7f67a49d1f4",
|
|
9
|
+
"GUID:57a0b9bc628ab4740af4b6f1f0b2e134"
|
|
10
|
+
],
|
|
11
|
+
"includePlatforms": [],
|
|
12
|
+
"excludePlatforms": [],
|
|
13
|
+
"allowUnsafeCode": false,
|
|
14
|
+
"overrideReferences": false,
|
|
15
|
+
"precompiledReferences": [],
|
|
16
|
+
"autoReferenced": true,
|
|
17
|
+
"defineConstraints": [],
|
|
18
|
+
"versionDefines": [],
|
|
19
|
+
"noEngineReferences": false
|
|
18
20
|
}
|