备份CatanBuilding瘦身独立工程
This commit is contained in:
56
LocalPackages/vibration/README.md
Normal file
56
LocalPackages/vibration/README.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# Installation
|
||||
|
||||
### Using OpenUPM (For Unity 2018.3 or later)
|
||||
|
||||
This package is available on [OpenUPM](https://openupm.com).
|
||||
You can install it via [openupm-cli](https://github.com/openupm/openupm-cli).
|
||||
|
||||
```
|
||||
openupm add com.unitypackage.vibration
|
||||
```
|
||||
|
||||
### Using Unity Package Manager (For Unity 2018.3 or later)
|
||||
|
||||
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
|
||||
|
||||
open Packages/manifest.json
|
||||
|
||||
```
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unitypackage.vibration":"https://github.com/UnityPackage/vibration.git",
|
||||
...
|
||||
},
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# Quick start
|
||||
```csharp
|
||||
|
||||
// Ios 需要在启动时候 初始化
|
||||
MMVibrationManager.iOSInitializeHaptics();
|
||||
|
||||
// 指定类型震动
|
||||
MMVibrationManager.Haptic(HapticTypes.*);
|
||||
|
||||
enum HapticTypes{
|
||||
Selection,
|
||||
Success,
|
||||
Warning,
|
||||
Failure,
|
||||
LightImpact,
|
||||
MediumImpact,
|
||||
HeavyImpact,
|
||||
}
|
||||
|
||||
// Update 1次调用1次 或者自定义重复调用持续震动
|
||||
Handheld.Vibrate();
|
||||
|
||||
```
|
||||
|
||||
|
||||
# link
|
||||
- [Unity Custom Packages](https://docs.unity3d.com/Manual/CustomPackages.html)
|
||||
|
||||
|
||||
7
LocalPackages/vibration/README.md.meta
Normal file
7
LocalPackages/vibration/README.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb51da4f6bccd41c487e2c5e76d22414
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
LocalPackages/vibration/ThirdParties.meta
Normal file
8
LocalPackages/vibration/ThirdParties.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2da7d6a976880e4aa39f9db420af80c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
LocalPackages/vibration/ThirdParties/NiceVibrations.meta
Normal file
8
LocalPackages/vibration/ThirdParties/NiceVibrations.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac51bbe0bc6154bb8b8094a48a5e7951
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19b4531dece6e498bac8d15efb375677
|
||||
folderAsset: yes
|
||||
timeCreated: 1514917649
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1b75a12c93e6496abd639012a7cf98f
|
||||
folderAsset: yes
|
||||
timeCreated: 1476095876
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99fbf16d5934a416a85df17b7891f64f
|
||||
folderAsset: yes
|
||||
timeCreated: 1476095881
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,132 @@
|
||||
// This iOS haptic interface is a pretty straightforward implementation of UIKit's framework :
|
||||
// You can learn more about these methods at https://developer.apple.com/documentation/uikit/animation_and_haptics
|
||||
// DO NOT remove this from your project, or iOS vibrations won't work anymore!
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
UISelectionFeedbackGenerator* SelectionFeedbackGenerator;
|
||||
UINotificationFeedbackGenerator* NotificationFeedbackGenerator;
|
||||
UIImpactFeedbackGenerator* LightImpactFeedbackGenerator;
|
||||
UIImpactFeedbackGenerator* MediumImpactFeedbackGenerator;
|
||||
UIImpactFeedbackGenerator* HeavyImpactFeedbackGenerator;
|
||||
UIImpactFeedbackGenerator* SoftImpactFeedbackGenerator;
|
||||
UIImpactFeedbackGenerator* RigidImpactFeedbackGenerator;
|
||||
|
||||
// INIT METHOD ---------------------------------------------------------------------------
|
||||
|
||||
void InstantiateFeedbackGenerators()
|
||||
{
|
||||
SelectionFeedbackGenerator = [[UISelectionFeedbackGenerator alloc] init];
|
||||
NotificationFeedbackGenerator = [[UINotificationFeedbackGenerator alloc] init];
|
||||
LightImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleLight];
|
||||
MediumImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];
|
||||
HeavyImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleHeavy];
|
||||
SoftImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleSoft];
|
||||
RigidImpactFeedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleRigid];
|
||||
}
|
||||
|
||||
// RELEASE METHOD ---------------------------------------------------------------------------
|
||||
|
||||
void ReleaseFeedbackGenerators ()
|
||||
{
|
||||
SelectionFeedbackGenerator = nil;
|
||||
NotificationFeedbackGenerator = nil;
|
||||
LightImpactFeedbackGenerator = nil;
|
||||
MediumImpactFeedbackGenerator = nil;
|
||||
HeavyImpactFeedbackGenerator = nil;
|
||||
SoftImpactFeedbackGenerator = nil;
|
||||
RigidImpactFeedbackGenerator = nil;
|
||||
}
|
||||
|
||||
// PREPARATION METHODS ----------------------------------------------------------------------
|
||||
|
||||
void PrepareSelectionFeedbackGenerator()
|
||||
{
|
||||
[SelectionFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareNotificationFeedbackGenerator()
|
||||
{
|
||||
[NotificationFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareLightImpactFeedbackGenerator()
|
||||
{
|
||||
[LightImpactFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareMediumImpactFeedbackGenerator()
|
||||
{
|
||||
[MediumImpactFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareHeavyImpactFeedbackGenerator()
|
||||
{
|
||||
[HeavyImpactFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareSoftImpactFeedbackGenerator()
|
||||
{
|
||||
[SoftImpactFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
void PrepareRigidImpactFeedbackGenerator()
|
||||
{
|
||||
[RigidImpactFeedbackGenerator prepare];
|
||||
}
|
||||
|
||||
// FEEDBACK TRIGGER METHODS -------------------------------------------------------------------------
|
||||
|
||||
void SelectionHaptic()
|
||||
{
|
||||
[SelectionFeedbackGenerator prepare];
|
||||
[SelectionFeedbackGenerator selectionChanged];
|
||||
}
|
||||
|
||||
void SuccessHaptic()
|
||||
{
|
||||
[NotificationFeedbackGenerator prepare];
|
||||
[NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeSuccess];
|
||||
}
|
||||
|
||||
void WarningHaptic()
|
||||
{
|
||||
[NotificationFeedbackGenerator prepare];
|
||||
[NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeWarning];
|
||||
}
|
||||
|
||||
void FailureHaptic()
|
||||
{
|
||||
[NotificationFeedbackGenerator prepare];
|
||||
[NotificationFeedbackGenerator notificationOccurred:UINotificationFeedbackTypeError];
|
||||
}
|
||||
|
||||
void LightImpactHaptic()
|
||||
{
|
||||
[LightImpactFeedbackGenerator prepare];
|
||||
[LightImpactFeedbackGenerator impactOccurred];
|
||||
}
|
||||
|
||||
void MediumImpactHaptic()
|
||||
{
|
||||
[MediumImpactFeedbackGenerator prepare];
|
||||
[MediumImpactFeedbackGenerator impactOccurred];
|
||||
}
|
||||
|
||||
void HeavyImpactHaptic()
|
||||
{
|
||||
[HeavyImpactFeedbackGenerator prepare];
|
||||
[HeavyImpactFeedbackGenerator impactOccurred];
|
||||
}
|
||||
|
||||
void SoftImpactHaptic()
|
||||
{
|
||||
[SoftImpactFeedbackGenerator prepare];
|
||||
[SoftImpactFeedbackGenerator impactOccurred];
|
||||
}
|
||||
|
||||
void RigidImpactHaptic()
|
||||
{
|
||||
[RigidImpactFeedbackGenerator prepare];
|
||||
[RigidImpactFeedbackGenerator impactOccurred];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7d619733c7b84d74bf48f308046fd0b
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 0
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
DefaultValueInitialized: true
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42f03fcbaf27f4e0b8661f490cdd8754
|
||||
folderAsset: yes
|
||||
timeCreated: 1514912150
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,470 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#if UNITY_IOS
|
||||
using UnityEngine.iOS;
|
||||
#endif
|
||||
|
||||
public enum HapticTypes { Selection, Success, Warning, Failure, LightImpact, MediumImpact, HeavyImpact, SoftImpact, RigidImpact, Vibrate }
|
||||
|
||||
namespace MoreMountains.NiceVibrations
|
||||
{
|
||||
/// <summary>
|
||||
/// This class will allow you to trigger vibrations and haptic feedbacks on both iOS and Android,
|
||||
/// or on each specific platform independently.
|
||||
///
|
||||
/// For haptics patterns, it takes inspiration from the iOS guidelines :
|
||||
/// https://developer.apple.com/ios/human-interface-guidelines/user-interaction/feedback
|
||||
/// Of course the iOS haptics are called directly as they are, and they're crudely reproduced on Android.
|
||||
/// Feel free to tweak the patterns or create your own.
|
||||
///
|
||||
/// Here's a brief overview of the patterns :
|
||||
///
|
||||
/// - selection : light
|
||||
/// - success : light / heavy
|
||||
/// - warning : heavy / medium
|
||||
/// - failure : medium / medium / heavy / light
|
||||
/// - light
|
||||
/// - medium
|
||||
/// - heavy
|
||||
///
|
||||
/// </summary>
|
||||
public static class MMVibrationManager
|
||||
{
|
||||
// INTERFACE ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
public static long SoftDuration = 20;
|
||||
public static long RigidDuration = 20;
|
||||
public static long LightDuration = 20;
|
||||
public static long MediumDuration = 40;
|
||||
public static long HeavyDuration = 80;
|
||||
public static int SoftAmplitude = 10;
|
||||
public static int RigidAmplitude = 120;
|
||||
public static int LightAmplitude = 40;
|
||||
public static int MediumAmplitude = 120;
|
||||
public static int HeavyAmplitude = 255;
|
||||
private static int _sdkVersion = -1;
|
||||
private static long[] _successPattern = { 0, LightDuration, LightDuration, HeavyDuration };
|
||||
private static int[] _successPatternAmplitude = { 0, LightAmplitude, 0, HeavyAmplitude };
|
||||
private static long[] _warningPattern = { 0, HeavyDuration, LightDuration, MediumDuration };
|
||||
private static int[] _warningPatternAmplitude = { 0, HeavyAmplitude, 0, MediumAmplitude };
|
||||
private static long[] _failurePattern = { 0, MediumDuration, LightDuration, MediumDuration, LightDuration, HeavyDuration, LightDuration, LightDuration };
|
||||
private static int[] _failurePatternAmplitude = { 0, MediumAmplitude, 0, MediumAmplitude, 0, HeavyAmplitude, 0, LightAmplitude };
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the current platform is Android, false otherwise.
|
||||
/// </summary>
|
||||
public static bool Android()
|
||||
{
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the current platform is iOS, false otherwise
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if O was ied, <c>false</c> otherwise.</returns>
|
||||
public static bool iOS()
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers a simple vibration
|
||||
/// </summary>
|
||||
public static void Vibrate()
|
||||
{
|
||||
if (Android())
|
||||
{
|
||||
AndroidVibrate(MediumDuration);
|
||||
}
|
||||
else if (iOS())
|
||||
{
|
||||
iOSTriggerHaptics(HapticTypes.MediumImpact);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers a haptic feedback of the specified type
|
||||
/// </summary>
|
||||
/// <param name="type">Type.</param>
|
||||
public static void Haptic(HapticTypes type)
|
||||
{
|
||||
if (Android())
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case HapticTypes.Selection:
|
||||
AndroidVibrate(LightDuration, LightAmplitude);
|
||||
break;
|
||||
|
||||
case HapticTypes.Success:
|
||||
AndroidVibrate(_successPattern, _successPatternAmplitude, -1);
|
||||
break;
|
||||
|
||||
case HapticTypes.Warning:
|
||||
AndroidVibrate(_warningPattern, _warningPatternAmplitude, -1);
|
||||
break;
|
||||
|
||||
case HapticTypes.Failure:
|
||||
AndroidVibrate(_failurePattern, _failurePatternAmplitude, -1);
|
||||
break;
|
||||
|
||||
case HapticTypes.LightImpact:
|
||||
AndroidVibrate(LightDuration, LightAmplitude);
|
||||
break;
|
||||
|
||||
case HapticTypes.MediumImpact:
|
||||
AndroidVibrate(MediumDuration, MediumAmplitude);
|
||||
break;
|
||||
|
||||
case HapticTypes.HeavyImpact:
|
||||
AndroidVibrate(HeavyDuration, HeavyAmplitude);
|
||||
break;
|
||||
|
||||
case HapticTypes.SoftImpact:
|
||||
AndroidVibrate(SoftDuration, SoftAmplitude);
|
||||
break;
|
||||
|
||||
case HapticTypes.RigidImpact:
|
||||
AndroidVibrate(RigidDuration, RigidAmplitude);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (iOS())
|
||||
{
|
||||
iOSTriggerHaptics(type);
|
||||
}
|
||||
}
|
||||
|
||||
// INTERFACE END ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// Android ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
// Android Vibration reference can be found at :
|
||||
// https://developer.android.com/reference/android/os/Vibrator.html
|
||||
// And there starting v26, with support for amplitude :
|
||||
// https://developer.android.com/reference/android/os/VibrationEffect.html
|
||||
|
||||
#if UNITY_ANDROID && !UNITY_EDITOR
|
||||
private static AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
||||
private static AndroidJavaObject CurrentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
|
||||
private static AndroidJavaObject AndroidVibrator = CurrentActivity.Call<AndroidJavaObject>("getSystemService", "vibrator");
|
||||
private static AndroidJavaClass VibrationEffectClass;
|
||||
private static AndroidJavaObject VibrationEffect;
|
||||
private static int DefaultAmplitude;
|
||||
#else
|
||||
private static AndroidJavaClass UnityPlayer;
|
||||
private static AndroidJavaObject CurrentActivity;
|
||||
private static AndroidJavaObject AndroidVibrator = null;
|
||||
private static AndroidJavaClass VibrationEffectClass = null;
|
||||
private static AndroidJavaObject VibrationEffect;
|
||||
private static int DefaultAmplitude;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Requests a default vibration on Android, for the specified duration, in milliseconds
|
||||
/// </summary>
|
||||
/// <param name="milliseconds">Milliseconds.</param>
|
||||
public static void AndroidVibrate(long milliseconds)
|
||||
{
|
||||
if (!Android()) { return; }
|
||||
AndroidVibrator.Call("vibrate", milliseconds);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests a vibration of the specified amplitude and duration. If amplitude is not supported by the device's SDK, a default vibration will be requested
|
||||
/// </summary>
|
||||
/// <param name="milliseconds">Milliseconds.</param>
|
||||
/// <param name="amplitude">Amplitude.</param>
|
||||
public static void AndroidVibrate(long milliseconds, int amplitude)
|
||||
{
|
||||
if (!Android()) { return; }
|
||||
// amplitude is only supported
|
||||
if ((AndroidSDKVersion() < 26))
|
||||
{
|
||||
AndroidVibrate(milliseconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
VibrationEffectClassInitialization();
|
||||
VibrationEffect = VibrationEffectClass.CallStatic<AndroidJavaObject>("createOneShot", new object[] { milliseconds, amplitude });
|
||||
AndroidVibrator.Call("vibrate", VibrationEffect);
|
||||
}
|
||||
}
|
||||
|
||||
// Requests a vibration on Android for the specified pattern and optional repeat
|
||||
// Straight out of the Android documentation :
|
||||
// Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds.
|
||||
// The first value indicates the number of milliseconds to wait before turning the vibrator on.
|
||||
// The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off.
|
||||
// Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
|
||||
// repeat: the index into pattern at which to repeat, or -1 if you don't want to repeat.
|
||||
public static void AndroidVibrate(long[] pattern, int repeat)
|
||||
{
|
||||
if (!Android()) { return; }
|
||||
if ((AndroidSDKVersion() < 26))
|
||||
{
|
||||
AndroidVibrator.Call("vibrate", pattern, repeat);
|
||||
}
|
||||
else
|
||||
{
|
||||
VibrationEffectClassInitialization();
|
||||
VibrationEffect = VibrationEffectClass.CallStatic<AndroidJavaObject>("createWaveform", new object[] { pattern, repeat });
|
||||
AndroidVibrator.Call("vibrate", VibrationEffect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests a vibration on Android for the specified pattern, amplitude and optional repeat
|
||||
/// </summary>
|
||||
/// <param name="pattern">Pattern.</param>
|
||||
/// <param name="amplitudes">Amplitudes.</param>
|
||||
/// <param name="repeat">Repeat.</param>
|
||||
public static void AndroidVibrate(long[] pattern, int[] amplitudes, int repeat)
|
||||
{
|
||||
if (!Android()) { return; }
|
||||
if ((AndroidSDKVersion() < 26))
|
||||
{
|
||||
AndroidVibrator.Call("vibrate", pattern, repeat);
|
||||
}
|
||||
else
|
||||
{
|
||||
VibrationEffectClassInitialization();
|
||||
VibrationEffect = VibrationEffectClass.CallStatic<AndroidJavaObject>("createWaveform", new object[] { pattern, amplitudes, repeat });
|
||||
AndroidVibrator.Call("vibrate", VibrationEffect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stops all Android vibrations that may be active
|
||||
/// </summary>
|
||||
public static void AndroidCancelVibrations()
|
||||
{
|
||||
if (!Android()) { return; }
|
||||
AndroidVibrator.Call("cancel");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the VibrationEffectClass if needed.
|
||||
/// </summary>
|
||||
private static void VibrationEffectClassInitialization()
|
||||
{
|
||||
if (VibrationEffectClass == null) { VibrationEffectClass = new AndroidJavaClass("android.os.VibrationEffect"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current Android SDK version as an int
|
||||
/// </summary>
|
||||
/// <returns>The SDK version.</returns>
|
||||
public static int AndroidSDKVersion()
|
||||
{
|
||||
if (_sdkVersion == -1)
|
||||
{
|
||||
int apiLevel = int.Parse(SystemInfo.operatingSystem.Substring(SystemInfo.operatingSystem.IndexOf("-") + 1, 3));
|
||||
_sdkVersion = apiLevel;
|
||||
return apiLevel;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _sdkVersion;
|
||||
}
|
||||
}
|
||||
|
||||
// Android End ---------------------------------------------------------------------------------------------------------
|
||||
|
||||
// iOS ----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
// The following will only work if the iOSHapticInterface.m file is in a Plugins folder in your project.
|
||||
// It's a pretty straightforward implementation of iOS's UIFeedbackGenerator's methods.
|
||||
// You can learn more about them there : https://developer.apple.com/documentation/uikit/uifeedbackgenerator
|
||||
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
private static extern void InstantiateFeedbackGenerators();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void ReleaseFeedbackGenerators();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SelectionHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SuccessHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void WarningHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void FailureHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void LightImpactHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void MediumImpactHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void HeavyImpactHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void SoftImpactHaptic();
|
||||
[DllImport("__Internal")]
|
||||
private static extern void RigidImpactHaptic();
|
||||
#else
|
||||
private static void InstantiateFeedbackGenerators() { }
|
||||
private static void ReleaseFeedbackGenerators() { }
|
||||
private static void SelectionHaptic() { }
|
||||
private static void SuccessHaptic() { }
|
||||
private static void WarningHaptic() { }
|
||||
private static void FailureHaptic() { }
|
||||
private static void LightImpactHaptic() { }
|
||||
private static void MediumImpactHaptic() { }
|
||||
private static void HeavyImpactHaptic() { }
|
||||
private static void SoftImpactHaptic() { }
|
||||
private static void RigidImpactHaptic() { }
|
||||
#endif
|
||||
|
||||
private static bool iOSHapticsInitialized = false;
|
||||
|
||||
/// <summary>
|
||||
/// Call this method to initialize the haptics. If you forget to do it, Nice Vibrations will do it for you the first time you
|
||||
/// call iOSTriggerHaptics. It's better if you do it though.
|
||||
/// </summary>
|
||||
public static void iOSInitializeHaptics()
|
||||
{
|
||||
if (!iOS()) { return; }
|
||||
|
||||
Debug.Log("[MMVibrationManager::iOSInitializeHaptics] iOSInitializeHaptics");
|
||||
InstantiateFeedbackGenerators();
|
||||
iOSHapticsInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Releases the feedback generators, usually you'll want to call this at OnDisable(); or anytime you know you won't need
|
||||
/// vibrations anymore.
|
||||
/// </summary>
|
||||
public static void iOSReleaseHaptics()
|
||||
{
|
||||
if (!iOS()) { return; }
|
||||
ReleaseFeedbackGenerators();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This methods tests the current device generation against a list of devices that don't support haptics, and returns true if haptics are supported, false otherwise.
|
||||
/// </summary>
|
||||
/// <returns><c>true</c>, if supported was hapticsed, <c>false</c> otherwise.</returns>
|
||||
public static bool HapticsSupported()
|
||||
{
|
||||
bool hapticsSupported = false;
|
||||
#if UNITY_IOS
|
||||
DeviceGeneration generation = Device.generation;
|
||||
if ((generation == DeviceGeneration.iPhone3G)
|
||||
|| (generation == DeviceGeneration.iPhone3GS)
|
||||
|| (generation == DeviceGeneration.iPodTouch1Gen)
|
||||
|| (generation == DeviceGeneration.iPodTouch2Gen)
|
||||
|| (generation == DeviceGeneration.iPodTouch3Gen)
|
||||
|| (generation == DeviceGeneration.iPodTouch4Gen)
|
||||
|| (generation == DeviceGeneration.iPhone4)
|
||||
|| (generation == DeviceGeneration.iPhone4S)
|
||||
|| (generation == DeviceGeneration.iPhone5)
|
||||
|| (generation == DeviceGeneration.iPhone5C)
|
||||
|| (generation == DeviceGeneration.iPhone5S)
|
||||
|| (generation == DeviceGeneration.iPhone6)
|
||||
|| (generation == DeviceGeneration.iPhone6Plus)
|
||||
|| (generation == DeviceGeneration.iPhone6S)
|
||||
|| (generation == DeviceGeneration.iPhone6SPlus))
|
||||
{
|
||||
hapticsSupported = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hapticsSupported = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return hapticsSupported;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// iOS only : triggers a haptic feedback of the specified type
|
||||
/// </summary>
|
||||
/// <param name="type">Type.</param>
|
||||
public static void iOSTriggerHaptics(HapticTypes type)
|
||||
{
|
||||
if (!iOS()) { return; }
|
||||
|
||||
if (!iOSHapticsInitialized)
|
||||
{
|
||||
iOSInitializeHaptics();
|
||||
}
|
||||
|
||||
// this will trigger a standard vibration on all the iOS devices that don't support haptic feedback
|
||||
|
||||
if (HapticsSupported())
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case HapticTypes.Selection:
|
||||
SelectionHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.Success:
|
||||
SuccessHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.Warning:
|
||||
WarningHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.Failure:
|
||||
FailureHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.LightImpact:
|
||||
LightImpactHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.MediumImpact:
|
||||
MediumImpactHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.HeavyImpact:
|
||||
HeavyImpactHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.SoftImpact:
|
||||
SoftImpactHaptic();
|
||||
break;
|
||||
|
||||
case HapticTypes.RigidImpact:
|
||||
RigidImpactHaptic();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#if UNITY_IOS
|
||||
Handheld.Vibrate();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string containing iOS SDK informations
|
||||
/// </summary>
|
||||
/// <returns>The OSSDK version.</returns>
|
||||
public static string iOSSDKVersion()
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
return Device.systemVersion;
|
||||
#else
|
||||
return null;
|
||||
#endif
|
||||
}
|
||||
|
||||
// iOS End ----------------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e5c5e5775047421a958e66bc6e9f102
|
||||
timeCreated: 1514906462
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
A more user friendly doc is available at http://nice-vibrations-docs.moremountains.com/
|
||||
Find out more about the asset at http://nice-vibrations.moremountains.com/
|
||||
|
||||
Nice Vibrations v1.2
|
||||
|
||||
## WHAT'S IN THE ASSET ?
|
||||
-------------------------
|
||||
|
||||
The asset contains two main folders : Common and Demos. As the name implies, Common contains all the scripts necessary for the mobile vibrations to work. You'll want to keep that folder in your game.
|
||||
|
||||
Demos contains a demo scene meant to be compiled for Android or iOS.
|
||||
|
||||
|
||||
## HOW DO I ADD THIS TO MY GAME ?
|
||||
------------------------------
|
||||
|
||||
You should probably go check out http://nice-vibrations-docs.moremountains.com/, there'll be more details, but basically all you need is to import the asset into your project, and you can instantly call the vibration methods from anywhere in your code. No need to add anything to your scenes. Nice Vibrations comes with universal methods (that will target both iOS and Android in one line), or specific ones to get more tailored results on each platform.
|
||||
|
||||
## IS THERE DOCUMENTATION SOMEWHERE ?
|
||||
-------------------------------------
|
||||
|
||||
There is!
|
||||
There's a functional documentation at http://nice-vibrations-docs.moremountains.com/
|
||||
And a complete API documentation at http://nice-vibrations-docs.moremountains.com/API/
|
||||
|
||||
## I STILL HAVE A QUESTION!
|
||||
---------------------------
|
||||
|
||||
If something's still not clear, you can always drop me a line using the form at http://nice-vibrations.moremountains.com/. It's entirely possible that I forgot to document something, but please make sure you've read the documentation before filling this form. You can also please check the FAQ before sending me an email. Chances are, your question's answered right there. If it's not, then go ahead!
|
||||
Also, if you're asking for support, please send me your invoice number, along with your Unity version and the version of Nice Vibrations you're using, so I can help you best.
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 282b96364e97a2749b507185b76f4852
|
||||
timeCreated: 1515124842
|
||||
licenseType: Store
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
3
LocalPackages/vibration/Vibration.asmdef
Normal file
3
LocalPackages/vibration/Vibration.asmdef
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Vibration"
|
||||
}
|
||||
7
LocalPackages/vibration/Vibration.asmdef.meta
Normal file
7
LocalPackages/vibration/Vibration.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d18feda6d5564655a96c73b42dc27a5
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
LocalPackages/vibration/package.json
Normal file
8
LocalPackages/vibration/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "com.unitypackage.vibration",
|
||||
"displayName": "Vibration",
|
||||
"description": "Vibration",
|
||||
"unity": "2019.2",
|
||||
"dependencies": {},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
7
LocalPackages/vibration/package.json.meta
Normal file
7
LocalPackages/vibration/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4e60a1187c2c4908b9a370d4dfb97ff
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user