diff --git a/CandyCoded.HapticFeedback.asmdef b/CandyCoded.HapticFeedback.asmdef new file mode 100644 index 0000000..c22b23a --- /dev/null +++ b/CandyCoded.HapticFeedback.asmdef @@ -0,0 +1,20 @@ +{ + "name": "CandyCoded.HapticFeedback", + "references": [ + "CandyCoded.HapticFeedback.Android", + "CandyCoded.HapticFeedback.iOS" + ], + "includePlatforms": [ + "Android", + "Editor", + "iOS" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/CandyCoded.HapticFeedback.asmdef.meta b/CandyCoded.HapticFeedback.asmdef.meta new file mode 100644 index 0000000..1a52253 --- /dev/null +++ b/CandyCoded.HapticFeedback.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b7a16d9f27dfd4770805a4cdc942c190 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins.meta b/Plugins.meta new file mode 100644 index 0000000..a23fa42 --- /dev/null +++ b/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 97d835e4469eb4b2f8b0461a24d3f14f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android.meta b/Plugins/Android.meta new file mode 100644 index 0000000..d2392a4 --- /dev/null +++ b/Plugins/Android.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fbf42de6d3d274567ab7c62ee17bbecf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef b/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef new file mode 100644 index 0000000..a56fc6d --- /dev/null +++ b/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef @@ -0,0 +1,16 @@ +{ + "name": "CandyCoded.HapticFeedback.Android", + "references": [], + "includePlatforms": [ + "Android", + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef.meta b/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef.meta new file mode 100644 index 0000000..f5de39b --- /dev/null +++ b/Plugins/Android/CandyCoded.HapticFeedback.Android.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 554646506760c444e8c83e5eb5416a5e +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/HapticFeedback.cs b/Plugins/Android/HapticFeedback.cs new file mode 100644 index 0000000..9414200 --- /dev/null +++ b/Plugins/Android/HapticFeedback.cs @@ -0,0 +1,81 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace CandyCoded.HapticFeedback.Android +{ + + public enum HapticFeedbackConstants + { + + LONG_PRESS = 0, + + VIRTUAL_KEY = 1, + + KEYBOARD_TAP = 3, + + CLOCK_TICK = 4, + + CALENDAR_DATE = 5, + + CONTEXT_CLICK = 6, + + KEYBOARD_PRESS = KEYBOARD_TAP, + + KEYBOARD_RELEASE = 7, + + VIRTUAL_KEY_RELEASE = 8, + + TEXT_HANDLE_MOVE = 9, + + ENTRY_BUMP = 10, + + DRAG_CROSSING = 11, + + GESTURE_START = 12, + + GESTURE_END = 13, + + EDGE_SQUEEZE = 14, + + EDGE_RELEASE = 15, + + CONFIRM = 16, + + REJECT = 17 + + } + + public static class HapticFeedback + { + + private static AndroidJavaObject _androidPlugin; + + private static AndroidJavaObject androidPlugin + { + get + { + if (_androidPlugin != null) + { + return _androidPlugin; + } + + var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); + + var currentActivity = javaUnityPlayer.GetStatic("currentActivity"); + + _androidPlugin = + new AndroidJavaObject("com.candycoded.hapticfeedbacklibrary.AndroidPlugin", currentActivity); + + return _androidPlugin; + } + } + + public static void PerformHapticFeedback(HapticFeedbackConstants hapticFeedbackConstants) + { + androidPlugin.Call("PerformHapticFeedback", (int)hapticFeedbackConstants); + } + + } + +} diff --git a/Plugins/Android/HapticFeedback.cs.meta b/Plugins/Android/HapticFeedback.cs.meta new file mode 100644 index 0000000..d96bbce --- /dev/null +++ b/Plugins/Android/HapticFeedback.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5ec9890f607a44d4eaad3fdd1fd3e6a7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/hapticfeedbacklibrary-release.aar b/Plugins/Android/hapticfeedbacklibrary-release.aar new file mode 100644 index 0000000..e82d222 Binary files /dev/null and b/Plugins/Android/hapticfeedbacklibrary-release.aar differ diff --git a/Plugins/Android/hapticfeedbacklibrary-release.aar.meta b/Plugins/Android/hapticfeedbacklibrary-release.aar.meta new file mode 100644 index 0000000..065e69f --- /dev/null +++ b/Plugins/Android/hapticfeedbacklibrary-release.aar.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 054d57bbb5f55465096ec06954f10141 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 1 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Android: Android + second: + enabled: 1 + settings: {} + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS.meta b/Plugins/iOS.meta new file mode 100644 index 0000000..9587c49 --- /dev/null +++ b/Plugins/iOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 638e4e983493542f6849fd24ee9a2862 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef b/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef new file mode 100644 index 0000000..d4901e9 --- /dev/null +++ b/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef @@ -0,0 +1,16 @@ +{ + "name": "CandyCoded.HapticFeedback.iOS", + "references": [], + "includePlatforms": [ + "Editor", + "iOS" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef.meta b/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef.meta new file mode 100644 index 0000000..966e358 --- /dev/null +++ b/Plugins/iOS/CandyCoded.HapticFeedback.iOS.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: cf71d521a1fdb4048be474c17bc79276 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/HapticFeedback.cs b/Plugins/iOS/HapticFeedback.cs new file mode 100644 index 0000000..e3ae9f1 --- /dev/null +++ b/Plugins/iOS/HapticFeedback.cs @@ -0,0 +1,16 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Runtime.InteropServices; + +namespace CandyCoded.HapticFeedback.iOS +{ + + public static class HapticFeedback + { + + [DllImport("__Internal")] + public static extern void IOSUIImpactFeedbackGenerator(string style = "medium"); + + } + +} diff --git a/Plugins/iOS/HapticFeedback.cs.meta b/Plugins/iOS/HapticFeedback.cs.meta new file mode 100644 index 0000000..11ea130 --- /dev/null +++ b/Plugins/iOS/HapticFeedback.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e27355e2dfa348eba88cd78bd2074fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/HapticFeedback.mm b/Plugins/iOS/HapticFeedback.mm new file mode 100644 index 0000000..9596013 --- /dev/null +++ b/Plugins/iOS/HapticFeedback.mm @@ -0,0 +1,44 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +#import +#import + +extern "C" +{ + + void IOSUIImpactFeedbackGenerator(const char* style) { + + UIImpactFeedbackStyle feedbackStyle; + + const NSString* styleString = [NSString stringWithUTF8String: style]; + + if ([styleString isEqualToString:@"light"]) { + + feedbackStyle = UIImpactFeedbackStyleLight; + + } else if ([styleString isEqualToString:@"medium"]) { + + feedbackStyle = UIImpactFeedbackStyleMedium; + + } else if ([styleString isEqualToString:@"heavy"]) { + + feedbackStyle = UIImpactFeedbackStyleHeavy; + + } else { + + NSException* exception = [NSException + exceptionWithName:NSInvalidArgumentException + reason:@"Invalid impact feedback style." + userInfo:nil]; + + [exception raise]; + + } + + UIImpactFeedbackGenerator *feedbackGenerator = [[UIImpactFeedbackGenerator alloc] initWithStyle:feedbackStyle]; + + [feedbackGenerator impactOccurred]; + + } + +} diff --git a/Plugins/iOS/HapticFeedback.mm.meta b/Plugins/iOS/HapticFeedback.mm.meta new file mode 100644 index 0000000..5ac8451 --- /dev/null +++ b/Plugins/iOS/HapticFeedback.mm.meta @@ -0,0 +1,37 @@ +fileFormatVersion: 2 +guid: cf6bde5da48be4e3098956bab5c875c8 +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: {} + - first: + tvOS: tvOS + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts.meta b/Scripts.meta new file mode 100644 index 0000000..91d3ffa --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ed3f78531dd194cb4827379433f70455 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/HapticFeedback.cs b/Scripts/HapticFeedback.cs new file mode 100644 index 0000000..857ec9c --- /dev/null +++ b/Scripts/HapticFeedback.cs @@ -0,0 +1,44 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace CandyCoded.HapticFeedback +{ + + public static class HapticFeedback + { + + public static void LightFeedback() + { + +#if UNITY_IPHONE + iOS.HapticFeedback.IOSUIImpactFeedbackGenerator("light"); +#elif UNITY_ANDROID + Android.HapticFeedback.PerformHapticFeedback(Android.HapticFeedbackConstants.CONTEXT_CLICK); +#endif + + } + + public static void MediumFeedback() + { + +#if UNITY_IPHONE + iOS.HapticFeedback.IOSUIImpactFeedbackGenerator("medium"); +#elif UNITY_ANDROID + Android.HapticFeedback.PerformHapticFeedback(Android.HapticFeedbackConstants.VIRTUAL_KEY); +#endif + + } + + public static void HeavyFeedback() + { + +#if UNITY_IPHONE + iOS.HapticFeedback.IOSUIImpactFeedbackGenerator("heavy"); +#elif UNITY_ANDROID + Android.HapticFeedback.PerformHapticFeedback(Android.HapticFeedbackConstants.LONG_PRESS); +#endif + + } + + } + +} diff --git a/Scripts/HapticFeedback.cs.meta b/Scripts/HapticFeedback.cs.meta new file mode 100644 index 0000000..b193bbb --- /dev/null +++ b/Scripts/HapticFeedback.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3cd1e9b04b0714428ade3545be095652 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/HapticFeedbackController.cs b/Scripts/HapticFeedbackController.cs new file mode 100644 index 0000000..10b8611 --- /dev/null +++ b/Scripts/HapticFeedbackController.cs @@ -0,0 +1,28 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine; + +namespace CandyCoded.HapticFeedback +{ + + public class HapticFeedbackController : MonoBehaviour + { + + public void LightFeedback() + { + HapticFeedback.LightFeedback(); + } + + public void MediumFeedback() + { + HapticFeedback.MediumFeedback(); + } + + public void HeavyFeedback() + { + HapticFeedback.HeavyFeedback(); + } + + } + +} diff --git a/Scripts/HapticFeedbackController.cs.meta b/Scripts/HapticFeedbackController.cs.meta new file mode 100644 index 0000000..85ede3e --- /dev/null +++ b/Scripts/HapticFeedbackController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5405fdbcca07647b4a0a57550afac202 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..2623478 --- /dev/null +++ b/package.json @@ -0,0 +1,25 @@ +{ + "name": "xyz.candycoded.hapticfeedback", + "displayName": "Haptic Feedback", + "version": "1.0.0", + "unity": "2019.2", + "unityRelease": "0f1", + "description": "Perform haptic feedback on both iOS and Android devices.", + "license": "MIT", + "dependencies": {}, + "keywords": [ + "ios", + "android", + "haptic" + ], + "author": { + "name": "Scott Doxey", + "email": "hello@scottdoxey.com", + "homepage": "http://scottdoxey.com/" + }, + "homepage": "https://github.com/CandyCoded/HapticFeedback", + "repository": { + "type": "git", + "url": "git@github.com:CandyCoded/HapticFeedback.git" + } +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..cf7f507 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 16aa21212328d4243bf501d4389d8a19 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: