From 8bb1cbe888017160c20e4f9ec4bc89750a38111f Mon Sep 17 00:00:00 2001 From: neogeek Date: Sun, 22 Sep 2019 12:21:56 -0400 Subject: [PATCH] Renamed directory. --- CandyCoded.UnityiOSBridge.asmdef | 15 ++ CandyCoded.UnityiOSBridge.asmdef.meta | 7 + Plugins.meta | 8 + Plugins/iOS.meta | 8 + Plugins/iOS/IOSBridge.cs | 160 +++++++++++++++++++ Plugins/iOS/IOSBridge.cs.meta | 11 ++ Plugins/iOS/IOSBridge.mm | 211 ++++++++++++++++++++++++++ Plugins/iOS/IOSBridge.mm.meta | 32 ++++ Plugins/iOS/IOSBridgeEvents.cs | 23 +++ Plugins/iOS/IOSBridgeEvents.cs.meta | 11 ++ package.json | 23 +++ package.json.meta | 7 + 12 files changed, 516 insertions(+) create mode 100644 CandyCoded.UnityiOSBridge.asmdef create mode 100644 CandyCoded.UnityiOSBridge.asmdef.meta create mode 100644 Plugins.meta create mode 100644 Plugins/iOS.meta create mode 100644 Plugins/iOS/IOSBridge.cs create mode 100644 Plugins/iOS/IOSBridge.cs.meta create mode 100644 Plugins/iOS/IOSBridge.mm create mode 100644 Plugins/iOS/IOSBridge.mm.meta create mode 100644 Plugins/iOS/IOSBridgeEvents.cs create mode 100644 Plugins/iOS/IOSBridgeEvents.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/CandyCoded.UnityiOSBridge.asmdef b/CandyCoded.UnityiOSBridge.asmdef new file mode 100644 index 0000000..161d5ac --- /dev/null +++ b/CandyCoded.UnityiOSBridge.asmdef @@ -0,0 +1,15 @@ +{ + "name": "CandyCoded.UnityiOSBridge", + "references": [], + "includePlatforms": [ + "Editor", + "iOS" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [] +} \ No newline at end of file diff --git a/CandyCoded.UnityiOSBridge.asmdef.meta b/CandyCoded.UnityiOSBridge.asmdef.meta new file mode 100644 index 0000000..91e726a --- /dev/null +++ b/CandyCoded.UnityiOSBridge.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 30d670a322995478b97aa8d673ed1c9b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins.meta b/Plugins.meta new file mode 100644 index 0000000..c72bb80 --- /dev/null +++ b/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 337ab088c562e4b459237185cbb3540e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS.meta b/Plugins/iOS.meta new file mode 100644 index 0000000..b45448a --- /dev/null +++ b/Plugins/iOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 48745d55485fc4cd9b5e1c601d754d86 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/IOSBridge.cs b/Plugins/iOS/IOSBridge.cs new file mode 100644 index 0000000..486e923 --- /dev/null +++ b/Plugins/iOS/IOSBridge.cs @@ -0,0 +1,160 @@ +using System; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace CandyCoded.UnityIOSBridge +{ + + public static class Accessibility + { + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsAssistiveTouchRunning(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsVoiceOverRunning(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsSwitchControlRunning(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsShakeToUndoEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsClosedCaptioningEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsBoldTextEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityDarkerSystemColorsEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsGrayscaleEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsGuidedAccessEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsInvertColorsEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsMonoAudioEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsReduceMotionEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsReduceTransparencyEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsSpeakScreenEnabled(); + + [DllImport("__Internal")] + public static extern bool IOSUIAccessibilityIsSpeakSelectionEnabled(); + + } + + public static class Alert + { + + [DllImport("__Internal")] + private static extern void IOSUIAlertController(string title, string message, string okGameObjectName, string cancelGameObjectName); + + public static void IOSUIAlertController(string title, string message, Action okCallback, Action cancelCallback) + { + + var okGameObject = new GameObject("IOSBridgeEvents - UIAlertController - OK"); + var okBridgeEvents = okGameObject.AddComponent(); + okBridgeEvents.action += okCallback; + + var cancelGameObject = new GameObject("IOSBridgeEvents - UIAlertController - Cancel"); + var cancelBridgeEvents = cancelGameObject.AddComponent(); + cancelBridgeEvents.action += cancelCallback; + + okBridgeEvents.action += () => { + + UnityEngine.Object.Destroy(cancelGameObject); + + }; + + cancelBridgeEvents.action += () => { + + UnityEngine.Object.Destroy(okGameObject); + + }; + + IOSUIAlertController(title, message, okGameObject.name, cancelGameObject.name); + + } + + public static void IOSUIAlertController(string title, string message, Action okCallback) + { + + var okGameObject = new GameObject("IOSBridgeEvents - UIAlertController - OK"); + var okBridgeEvents = okGameObject.AddComponent(); + okBridgeEvents.action += okCallback; + + IOSUIAlertController(title, message, okGameObject.name, ""); + + } + + } + + public static class Permission + { + + [DllImport("__Internal")] + public static extern bool IOSPermissionCameraOK(); + + } + + public static class Photos + { + + [DllImport("__Internal")] + public static extern bool IOSImageAddToGallery(string path); + + } + + public static class Settings + { + + [DllImport("__Internal")] + public static extern bool IOSIsLowPowerModeEnabled(); + + [DllImport("__Internal")] + public static extern void IOSUIImpactFeedbackGenerator(string style = "medium"); + + } + + public static class View + { + + public struct UIEdgeInsets + { + public float top; + public float left; + public float right; + public float bottom; + } + + [DllImport("__Internal")] + private static extern float IOSSafeAreaInsets(string side); + + public static UIEdgeInsets IOSSafeAreaInsets() + { + + return new UIEdgeInsets + { + top = IOSSafeAreaInsets("top"), + left = IOSSafeAreaInsets("left"), + right = IOSSafeAreaInsets("right"), + bottom = IOSSafeAreaInsets("bottom") + }; + + } + + } + +} diff --git a/Plugins/iOS/IOSBridge.cs.meta b/Plugins/iOS/IOSBridge.cs.meta new file mode 100644 index 0000000..5ff7c29 --- /dev/null +++ b/Plugins/iOS/IOSBridge.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58bdf7b5c56d54cd581a784e377f2805 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/IOSBridge.mm b/Plugins/iOS/IOSBridge.mm new file mode 100644 index 0000000..04c9bdd --- /dev/null +++ b/Plugins/iOS/IOSBridge.mm @@ -0,0 +1,211 @@ +#import +#import +#import + +extern "C" +{ + + void IOSImageAddToGallery(const char* path) { + + NSString* fileString = [NSString stringWithUTF8String: path]; + + UIImage *image = [UIImage imageWithContentsOfFile:fileString]; + UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil); + + } + + bool IOSIsLowPowerModeEnabled() { + return [[NSProcessInfo processInfo] isLowPowerModeEnabled]; + } + + bool IOSPermissionCameraOK() { + + NSString *mediaType = AVMediaTypeVideo; + AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; + + return authStatus == AVAuthorizationStatusAuthorized; + + } + + float IOSSafeAreaInsets(const char* side) { + + if (@available(iOS 11.0, *)) { + + const NSString* sideString = [NSString stringWithUTF8String: side]; + + UIWindow *window = UIApplication.sharedApplication.keyWindow; + + if ([sideString isEqualToString:@"top"]) { + + return window.safeAreaInsets.top; + + } else if ([sideString isEqualToString:@"left"]) { + + return window.safeAreaInsets.left; + + } else if ([sideString isEqualToString:@"right"]) { + + return window.safeAreaInsets.right; + + } else if ([sideString isEqualToString:@"bottom"]) { + + return window.safeAreaInsets.bottom; + + } else { + + NSException* exception = [NSException + exceptionWithName:NSInvalidArgumentException + reason:@"Invalid side value." + userInfo:nil]; + + [exception raise]; + + } + } + + NSException* exception = [NSException + exceptionWithName:NSInvalidArgumentException + reason:@"SafeArea only available on iOS 11+" + userInfo:nil]; + + [exception raise]; + + return false; + + } + + bool IOSUIAccessibilityIsAssistiveTouchRunning() { + return UIAccessibilityIsAssistiveTouchRunning(); + } + + bool IOSUIAccessibilityIsVoiceOverRunning() { + return UIAccessibilityIsVoiceOverRunning(); + } + + bool IOSUIAccessibilityIsSwitchControlRunning() { + return UIAccessibilityIsSwitchControlRunning(); + } + + bool IOSUIAccessibilityIsShakeToUndoEnabled() { + return UIAccessibilityIsShakeToUndoEnabled(); + } + + bool IOSUIAccessibilityIsClosedCaptioningEnabled() { + return UIAccessibilityIsClosedCaptioningEnabled(); + } + + bool IOSUIAccessibilityIsBoldTextEnabled() { + return UIAccessibilityIsBoldTextEnabled(); + } + + bool IOSUIAccessibilityDarkerSystemColorsEnabled() { + return UIAccessibilityDarkerSystemColorsEnabled(); + } + + bool IOSUIAccessibilityIsGrayscaleEnabled() { + return UIAccessibilityIsGrayscaleEnabled(); + } + + bool IOSUIAccessibilityIsGuidedAccessEnabled() { + return UIAccessibilityIsGuidedAccessEnabled(); + } + + bool IOSUIAccessibilityIsInvertColorsEnabled() { + return UIAccessibilityIsInvertColorsEnabled(); + } + + bool IOSUIAccessibilityIsMonoAudioEnabled() { + return UIAccessibilityIsMonoAudioEnabled(); + } + + bool IOSUIAccessibilityIsReduceMotionEnabled() { + return UIAccessibilityIsReduceMotionEnabled(); + } + + bool IOSUIAccessibilityIsReduceTransparencyEnabled() { + return UIAccessibilityIsReduceTransparencyEnabled(); + } + + bool IOSUIAccessibilityIsSpeakScreenEnabled() { + return UIAccessibilityIsSpeakScreenEnabled(); + } + + bool IOSUIAccessibilityIsSpeakSelectionEnabled() { + return UIAccessibilityIsSpeakSelectionEnabled(); + } + + void IOSUIAlertController(const char* title, const char* message, const char* okGameObjectName, const char* cancelGameObjectName) { + + NSString* titleString = [NSString stringWithUTF8String: title]; + NSString* messageString = [NSString stringWithUTF8String: message]; + + NSString* okGameObjectNameString = [NSString stringWithUTF8String: okGameObjectName]; + NSString* cancelGameObjectNameString = [NSString stringWithUTF8String: cancelGameObjectName]; + + UIAlertController* alert = [UIAlertController alertControllerWithTitle:titleString + message:messageString + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + UnitySendMessage([okGameObjectNameString UTF8String], "CallbackOneShot", ""); + + }]; + [alert addAction:defaultAction]; + + if ([cancelGameObjectNameString length] > 0) { + + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + + UnitySendMessage([cancelGameObjectNameString UTF8String], "CallbackOneShot", ""); + + }]; + [alert addAction:cancelAction]; + [alert setPreferredAction:defaultAction]; + + } + + UIViewController* view = [[[UIApplication sharedApplication] keyWindow] rootViewController]; + + [view presentViewController:alert animated:YES completion:nil]; + + } + + 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/IOSBridge.mm.meta b/Plugins/iOS/IOSBridge.mm.meta new file mode 100644 index 0000000..087d324 --- /dev/null +++ b/Plugins/iOS/IOSBridge.mm.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 37ffbbb25af2c43aca00bd20f6fb67fd +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + DefaultValueInitialized: true + - first: + iPhone: iOS + second: + enabled: 1 + settings: + AddToEmbeddedBinaries: false + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/IOSBridgeEvents.cs b/Plugins/iOS/IOSBridgeEvents.cs new file mode 100644 index 0000000..f4ec77a --- /dev/null +++ b/Plugins/iOS/IOSBridgeEvents.cs @@ -0,0 +1,23 @@ +using System; +using UnityEngine; + +namespace CandyCoded.UnityIOSBridge +{ + + public class IOSBridgeEvents : MonoBehaviour + { + + public Action action; + + public void CallbackOneShot() + { + + action?.Invoke(); + + Destroy(gameObject); + + } + + } + +} diff --git a/Plugins/iOS/IOSBridgeEvents.cs.meta b/Plugins/iOS/IOSBridgeEvents.cs.meta new file mode 100644 index 0000000..c65e6f1 --- /dev/null +++ b/Plugins/iOS/IOSBridgeEvents.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7d8a624af7240420c88dca08fcb51ae2 +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..d80b5e2 --- /dev/null +++ b/package.json @@ -0,0 +1,23 @@ +{ + "name": "xyz.candycoded.unity-ios-bridge", + "displayName": "Unity iOS Bridge", + "version": "1.1.0", + "unity": "2019.2", + "unityRelease": "2f1", + "description": "Bridge for requesting state from an iOS device", + "license": "MIT", + "dependencies": {}, + "keywords": [ + "ios" + ], + "author": { + "name": "Scott Doxey", + "email": "hello@scottdoxey.com", + "homepage": "http://scottdoxey.com/" + }, + "homepage": "https://github.com/CandyCoded/Unity-iOS-Bridge", + "repository": { + "type": "git", + "url": "git@github.com:CandyCoded/Unity-iOS-Bridge.git" + } +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..bc345dd --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 00bedb24664994ba6a34283b24419731 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: