-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathVibrationPreset.cs
More file actions
38 lines (31 loc) · 1.19 KB
/
VibrationPreset.cs
File metadata and controls
38 lines (31 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using Sirenix.OdinInspector;
using UnityEngine;
namespace Effects
{
[CreateAssetMenu]
public class VibrationPreset : ScriptableObject
{
[SerializeField] private long _durationMs = 1000;
[SerializeField, Range(-1, 255), ValidateInput(nameof(ValidateAmplitude))] private int _amplitude = -1;
public void Play()
{
if (DebugEnabled)
Debug.Log($"Vibration {name} has been played.", this);
Vibration.Vibrate(_durationMs, _amplitude);
}
private static bool ValidateAmplitude(int amplitude, ref string message)
{
if (1 <= amplitude && amplitude <= 255) return true;
if (amplitude == -1) return true;
message = "Amplitude must belong to [1; 255] or be equal to -1.";
return false;
}
[ShowInInspector, LabelText("Debug")]
public static bool DebugEnabled
{
get => PlayerPrefs.GetInt(DebugField, 0) == 1;
set => PlayerPrefs.SetInt(DebugField, value ? 1 : 0);
}
private const string DebugField = "Inspector_Debug_Vibration";
}
}