add project files
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OHM.UnityToolkit.Vibration
|
||||
{
|
||||
public class VibrationManager : MonoBehaviour
|
||||
{
|
||||
public static bool Enabled = true;
|
||||
|
||||
public static float MinDelay = 0.1f;
|
||||
|
||||
public static long AndroidSmallLen = 25L;
|
||||
|
||||
public static int AndroidSmallAmplitude = 64;
|
||||
|
||||
public static long AndroidMediumLen = 100L;
|
||||
|
||||
public static int AndroidMediumAmplitude = 128;
|
||||
|
||||
public static long AndroidBigLen = 300L;
|
||||
|
||||
public static int AndroidBigAmplitude = -1;
|
||||
|
||||
public static bool LogEnabled = true;
|
||||
|
||||
private static float _lastVibrationFrameTime = -1f;
|
||||
|
||||
private static VibrationType _lastVibrationType;
|
||||
|
||||
public static void Vibrate(VibrationType type)
|
||||
{
|
||||
if (!Enabled)
|
||||
{
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.Log("Vibration disabled");
|
||||
}
|
||||
return;
|
||||
}
|
||||
float sinceLast = Time.time - _lastVibrationFrameTime;
|
||||
if (sinceLast < MinDelay && _lastVibrationType >= type)
|
||||
{
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.LogFormat("Vibration ignored (lower or equal type {0} / {1} and delay not done {2}) ",
|
||||
type.ToString(), _lastVibrationType.ToString(), sinceLast);
|
||||
}
|
||||
return;
|
||||
}
|
||||
_lastVibrationFrameTime = Time.time;
|
||||
_lastVibrationType = type;
|
||||
long milliseconds;
|
||||
int amplitude;
|
||||
switch (type)
|
||||
{
|
||||
case VibrationType.BIG:
|
||||
milliseconds = AndroidBigLen;
|
||||
amplitude = AndroidBigAmplitude;
|
||||
break;
|
||||
case VibrationType.MEDIUM:
|
||||
milliseconds = AndroidMediumLen;
|
||||
amplitude = AndroidMediumAmplitude;
|
||||
break;
|
||||
case VibrationType.SMALL:
|
||||
milliseconds = AndroidSmallLen;
|
||||
amplitude = AndroidSmallAmplitude;
|
||||
break;
|
||||
default:
|
||||
milliseconds = 0L;
|
||||
amplitude = -1;
|
||||
break;
|
||||
}
|
||||
AndroidVibrationManager.CreateOneShot(milliseconds, amplitude);
|
||||
if (LogEnabled)
|
||||
{
|
||||
Debug.Log("Vibrate " + type.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public enum VibrationType
|
||||
{
|
||||
SMALL = 0,
|
||||
MEDIUM = 1,
|
||||
BIG = 2,
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b714271ca74f5b8532fca6341477a4b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user