From 54164f3daf5c08a02ef630441ea563e43af32ebe Mon Sep 17 00:00:00 2001 From: Scott Doxey Date: Wed, 24 Feb 2021 02:17:07 -0500 Subject: [PATCH] Initial commit. --- CandyCoded.AlertConfirmDialog.asmdef | 20 +++++ CandyCoded.AlertConfirmDialog.asmdef.meta | 7 ++ Plugins.meta | 8 ++ Plugins/Android.meta | 8 ++ Plugins/Android/AlertConfirmDialog.cs | 46 ++++++++++ Plugins/Android/AlertConfirmDialog.cs.meta | 3 + Plugins/Android/AndroidPlugin.java | 62 ++++++++++++++ Plugins/Android/AndroidPlugin.java.meta | 81 ++++++++++++++++++ ...ndyCoded.AlertConfirmDialog.Android.asmdef | 16 ++++ ...ded.AlertConfirmDialog.Android.asmdef.meta | 7 ++ Plugins/Android/androidplugin-release.aar | Bin 0 -> 2509 bytes .../Android/androidplugin-release.aar.meta | 32 +++++++ Plugins/iOS.meta | 8 ++ Plugins/iOS/AlertConfirmDialog.cs | 20 +++++ Plugins/iOS/AlertConfirmDialog.cs.meta | 11 +++ Plugins/iOS/AlertConfirmDialog.mm | 70 +++++++++++++++ Plugins/iOS/AlertConfirmDialog.mm.meta | 37 ++++++++ .../CandyCoded.AlertConfirmDialog.iOS.asmdef | 16 ++++ ...dyCoded.AlertConfirmDialog.iOS.asmdef.meta | 7 ++ Scripts.meta | 8 ++ Scripts/AlertConfirmDialog.cs | 65 ++++++++++++++ Scripts/AlertConfirmDialog.cs.meta | 11 +++ Scripts/UnitySendMessageEventHandler.cs | 39 +++++++++ Scripts/UnitySendMessageEventHandler.cs.meta | 11 +++ package.json | 29 +++++++ package.json.meta | 7 ++ 26 files changed, 629 insertions(+) create mode 100644 CandyCoded.AlertConfirmDialog.asmdef create mode 100644 CandyCoded.AlertConfirmDialog.asmdef.meta create mode 100644 Plugins.meta create mode 100644 Plugins/Android.meta create mode 100644 Plugins/Android/AlertConfirmDialog.cs create mode 100644 Plugins/Android/AlertConfirmDialog.cs.meta create mode 100644 Plugins/Android/AndroidPlugin.java create mode 100644 Plugins/Android/AndroidPlugin.java.meta create mode 100644 Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef create mode 100644 Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef.meta create mode 100644 Plugins/Android/androidplugin-release.aar create mode 100644 Plugins/Android/androidplugin-release.aar.meta create mode 100644 Plugins/iOS.meta create mode 100644 Plugins/iOS/AlertConfirmDialog.cs create mode 100644 Plugins/iOS/AlertConfirmDialog.cs.meta create mode 100644 Plugins/iOS/AlertConfirmDialog.mm create mode 100644 Plugins/iOS/AlertConfirmDialog.mm.meta create mode 100644 Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef create mode 100644 Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef.meta create mode 100644 Scripts.meta create mode 100644 Scripts/AlertConfirmDialog.cs create mode 100644 Scripts/AlertConfirmDialog.cs.meta create mode 100644 Scripts/UnitySendMessageEventHandler.cs create mode 100644 Scripts/UnitySendMessageEventHandler.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/CandyCoded.AlertConfirmDialog.asmdef b/CandyCoded.AlertConfirmDialog.asmdef new file mode 100644 index 0000000..161fcf8 --- /dev/null +++ b/CandyCoded.AlertConfirmDialog.asmdef @@ -0,0 +1,20 @@ +{ + "name": "CandyCoded.AlertConfirmDialog", + "references": [ + "CandyCoded.AlertConfirmDialog.Android", + "CandyCoded.AlertConfirmDialog.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.AlertConfirmDialog.asmdef.meta b/CandyCoded.AlertConfirmDialog.asmdef.meta new file mode 100644 index 0000000..9e325c1 --- /dev/null +++ b/CandyCoded.AlertConfirmDialog.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ba4a0950d8a4e441bb84796817307f5d +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins.meta b/Plugins.meta new file mode 100644 index 0000000..f1b0540 --- /dev/null +++ b/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 391fec1ddb7c945d8abf97096e6ace18 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android.meta b/Plugins/Android.meta new file mode 100644 index 0000000..7ff5103 --- /dev/null +++ b/Plugins/Android.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c0db598e993614f4a915d2f8b8ec42b7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/AlertConfirmDialog.cs b/Plugins/Android/AlertConfirmDialog.cs new file mode 100644 index 0000000..629451e --- /dev/null +++ b/Plugins/Android/AlertConfirmDialog.cs @@ -0,0 +1,46 @@ +// 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.AlertConfirmDialog.Android +{ + + public static class AlertConfirmDialog + { + + 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.alertconfirmdialog.AndroidPlugin", currentActivity); + + return _androidPlugin; + } + } + + public static void Alert(string title, string message, string okButtonLabel) + { + androidPlugin.Call("Alert", title, message, okButtonLabel); + } + + public static void Confirm(string title, string message, string okButtonLabel, + string cancelButtonLabel) + { + androidPlugin.Call("Confirm", title, message, okButtonLabel, cancelButtonLabel); + } + + } + +} diff --git a/Plugins/Android/AlertConfirmDialog.cs.meta b/Plugins/Android/AlertConfirmDialog.cs.meta new file mode 100644 index 0000000..aa72cf2 --- /dev/null +++ b/Plugins/Android/AlertConfirmDialog.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 387570baaf6540fb92c6108ee81516ea +timeCreated: 1613539850 \ No newline at end of file diff --git a/Plugins/Android/AndroidPlugin.java b/Plugins/Android/AndroidPlugin.java new file mode 100644 index 0000000..2363670 --- /dev/null +++ b/Plugins/Android/AndroidPlugin.java @@ -0,0 +1,62 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +package com.candycoded.alertconfirmdialog; + +import android.content.Context; +import android.app.AlertDialog; +import android.os.Bundle; + +import com.unity3d.player.UnityPlayer; + +public class AndroidPlugin { + + private Context context; + + public AndroidPlugin(Context context) { + this.context = context; + } + + public void Alert(String title, String message, String okButtonLabel) { + + AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); + + alertDialog.setTitle(title); + alertDialog.setMessage(message); + alertDialog.setPositiveButton(okButtonLabel, (dialog, which) -> { + + dialog.dismiss(); + + UnityPlayer.UnitySendMessage("AlertConfirmDialog", "Callback", "OK"); + + }); + alertDialog.create(); + alertDialog.show(); + + } + + public void Confirm(String title, String message, String okButtonLabel, String cancelButtonLabel) { + + AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); + + alertDialog.setTitle(title); + alertDialog.setMessage(message); + alertDialog.setPositiveButton(okButtonLabel, (dialog, which) -> { + + dialog.dismiss(); + + UnityPlayer.UnitySendMessage("AlertConfirmDialog", "Callback", "OK"); + + }); + alertDialog.setNegativeButton(cancelButtonLabel, (dialog, which) -> { + + dialog.dismiss(); + + UnityPlayer.UnitySendMessage("AlertConfirmDialog", "Callback", "CANCEL"); + + }); + alertDialog.create(); + alertDialog.show(); + + } + +} diff --git a/Plugins/Android/AndroidPlugin.java.meta b/Plugins/Android/AndroidPlugin.java.meta new file mode 100644 index 0000000..051103e --- /dev/null +++ b/Plugins/Android/AndroidPlugin.java.meta @@ -0,0 +1,81 @@ +fileFormatVersion: 2 +guid: 290b0c84318f14ef193b5a8a24125f62 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 1 + Exclude Linux64: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 1 + Exclude iOS: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: x86_64 + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: x86_64 + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: x86 + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: x86_64 + - first: + iPhone: iOS + second: + enabled: 0 + settings: + AddToEmbeddedBinaries: false + CPU: AnyCPU + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef b/Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef new file mode 100644 index 0000000..d5c173e --- /dev/null +++ b/Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef @@ -0,0 +1,16 @@ +{ + "name": "CandyCoded.AlertConfirmDialog.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.AlertConfirmDialog.Android.asmdef.meta b/Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef.meta new file mode 100644 index 0000000..35ca21e --- /dev/null +++ b/Plugins/Android/CandyCoded.AlertConfirmDialog.Android.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9ec7790458237408d96f3429328c7c8b +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/Android/androidplugin-release.aar b/Plugins/Android/androidplugin-release.aar new file mode 100644 index 0000000000000000000000000000000000000000..716781b14ddc6c04beb5cbae96e76a85461c5af0 GIT binary patch literal 2509 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 literal 0 HcmV?d00001 diff --git a/Plugins/Android/androidplugin-release.aar.meta b/Plugins/Android/androidplugin-release.aar.meta new file mode 100644 index 0000000..72ab261 --- /dev/null +++ b/Plugins/Android/androidplugin-release.aar.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: cf01909b86535413380ec48048b7ab98 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + 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..3d245e9 --- /dev/null +++ b/Plugins/iOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d35f73331e19041ec980dee228d02712 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/AlertConfirmDialog.cs b/Plugins/iOS/AlertConfirmDialog.cs new file mode 100644 index 0000000..9563557 --- /dev/null +++ b/Plugins/iOS/AlertConfirmDialog.cs @@ -0,0 +1,20 @@ +// 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.AlertConfirmDialog.iOS +{ + + public static class AlertConfirmDialog + { + + [DllImport("__Internal")] + public static extern void Alert(string title, string message, string okButtonLabel); + + [DllImport("__Internal")] + public static extern void Confirm(string title, string message, string okButtonLabel, + string cancelButtonLabel); + + } + +} diff --git a/Plugins/iOS/AlertConfirmDialog.cs.meta b/Plugins/iOS/AlertConfirmDialog.cs.meta new file mode 100644 index 0000000..22e1a9f --- /dev/null +++ b/Plugins/iOS/AlertConfirmDialog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 42a29b7453f034ef6aa7df6619c4730f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Plugins/iOS/AlertConfirmDialog.mm b/Plugins/iOS/AlertConfirmDialog.mm new file mode 100644 index 0000000..bddd9ab --- /dev/null +++ b/Plugins/iOS/AlertConfirmDialog.mm @@ -0,0 +1,70 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +#import +#import +#import + +extern "C" +{ + + void Alert(const char* title, const char* message, const char* okButtonLabel) { + + NSString* titleString = [NSString stringWithUTF8String: title]; + NSString* messageString = [NSString stringWithUTF8String: message]; + + NSString* okButtonLabelString = [NSString stringWithUTF8String: okButtonLabel]; + + UIAlertController* alert = [UIAlertController alertControllerWithTitle:titleString + message:messageString + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:okButtonLabelString style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + UnitySendMessage("AlertConfirmDialog", "Callback", "OK"); + + }]; + [alert addAction:defaultAction]; + + UIViewController* view = [[[UIApplication sharedApplication] keyWindow] rootViewController]; + + [view presentViewController:alert animated:YES completion:nil]; + + } + + void Confirm(const char* title, const char* message, const char* okButtonLabel, const char* cancelButtonLabel) { + + NSString* titleString = [NSString stringWithUTF8String: title]; + NSString* messageString = [NSString stringWithUTF8String: message]; + + NSString* okButtonLabelString = [NSString stringWithUTF8String: okButtonLabel]; + NSString* cancelButtonLabelString = [NSString stringWithUTF8String: cancelButtonLabel]; + + UIAlertController* alert = [UIAlertController alertControllerWithTitle:titleString + message:messageString + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:okButtonLabelString style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + UnitySendMessage("AlertConfirmDialog", "Callback", "OK"); + + }]; + [alert addAction:defaultAction]; + + UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:cancelButtonLabelString style:UIAlertActionStyleCancel + handler:^(UIAlertAction * action) { + + UnitySendMessage("AlertConfirmDialog", "Callback", "CANCEL"); + + }]; + [alert addAction:cancelAction]; + [alert setPreferredAction:defaultAction]; + + UIViewController* view = [[[UIApplication sharedApplication] keyWindow] rootViewController]; + + [view presentViewController:alert animated:YES completion:nil]; + + } + +} \ No newline at end of file diff --git a/Plugins/iOS/AlertConfirmDialog.mm.meta b/Plugins/iOS/AlertConfirmDialog.mm.meta new file mode 100644 index 0000000..0204a7f --- /dev/null +++ b/Plugins/iOS/AlertConfirmDialog.mm.meta @@ -0,0 +1,37 @@ +fileFormatVersion: 2 +guid: 349b383cb981443959172fb7c8c4391a +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/Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef b/Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef new file mode 100644 index 0000000..6dca854 --- /dev/null +++ b/Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef @@ -0,0 +1,16 @@ +{ + "name": "CandyCoded.AlertConfirmDialog.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.AlertConfirmDialog.iOS.asmdef.meta b/Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef.meta new file mode 100644 index 0000000..114100f --- /dev/null +++ b/Plugins/iOS/CandyCoded.AlertConfirmDialog.iOS.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 870c9fb6fd6b644b3bbd45a5490dd4b2 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts.meta b/Scripts.meta new file mode 100644 index 0000000..9b5c20c --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b317ee7df2d43463ba3b296fe1144513 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/AlertConfirmDialog.cs b/Scripts/AlertConfirmDialog.cs new file mode 100644 index 0000000..7480f77 --- /dev/null +++ b/Scripts/AlertConfirmDialog.cs @@ -0,0 +1,65 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using UnityEngine; + +namespace CandyCoded.AlertConfirmDialog +{ + + public static class AlertConfirmDialog + { + + private static UnitySendMessageEventHandler _unitySendMessageEventHandler; + + public static void Alert(string title, string message, Action okButtonCallback = null, + string okButtonLabel = "OK") + { + + if (_unitySendMessageEventHandler == null) + { + + var gameObject = new GameObject("AlertConfirmDialog", typeof(UnitySendMessageEventHandler)); + + gameObject.TryGetComponent(out _unitySendMessageEventHandler); + + } + + _unitySendMessageEventHandler.ok = okButtonCallback; + +#if UNITY_IOS && !UNITY_EDITOR + iOS.AlertConfirmDialog.Alert(title, message, okButtonLabel); +#elif UNITY_ANDROID && !UNITY_EDITOR + Android.AlertConfirmDialog.Alert(title, message, okButtonLabel); +#endif + + } + + public static void Confirm(string title, string message, Action okButtonCallback = null, + Action cancelButtonCallback = null, + string okButtonLabel = "OK", string cancelButtonLabel = "Cancel") + { + + if (_unitySendMessageEventHandler == null) + { + + var gameObject = new GameObject("AlertConfirmDialog", typeof(UnitySendMessageEventHandler)); + + gameObject.TryGetComponent(out _unitySendMessageEventHandler); + + } + + _unitySendMessageEventHandler.ok = okButtonCallback; + + _unitySendMessageEventHandler.cancel = cancelButtonCallback; + +#if UNITY_IOS && !UNITY_EDITOR + iOS.AlertConfirmDialog.Confirm(title, message, okButtonLabel, cancelButtonLabel); +#elif UNITY_ANDROID && !UNITY_EDITOR + Android.AlertConfirmDialog.Confirm(title, message, okButtonLabel, cancelButtonLabel); +#endif + + } + + } + +} diff --git a/Scripts/AlertConfirmDialog.cs.meta b/Scripts/AlertConfirmDialog.cs.meta new file mode 100644 index 0000000..280c583 --- /dev/null +++ b/Scripts/AlertConfirmDialog.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c6bc1d72e295849a0a72158c68c56d97 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/UnitySendMessageEventHandler.cs b/Scripts/UnitySendMessageEventHandler.cs new file mode 100644 index 0000000..9cd8af8 --- /dev/null +++ b/Scripts/UnitySendMessageEventHandler.cs @@ -0,0 +1,39 @@ +// Copyright (c) Scott Doxey. All Rights Reserved. Licensed under the MIT License. See LICENSE in the project root for license information. + +using System; +using UnityEngine; + +namespace CandyCoded.AlertConfirmDialog +{ + + public class UnitySendMessageEventHandler : MonoBehaviour + { + + public Action cancel; + + public Action ok; + + public void Callback(string message) + { + + switch (message) + { + case "OK": + ok?.Invoke(); + + break; + case "CANCEL": + cancel?.Invoke(); + + break; + } + + ok = null; + + cancel = null; + + } + + } + +} diff --git a/Scripts/UnitySendMessageEventHandler.cs.meta b/Scripts/UnitySendMessageEventHandler.cs.meta new file mode 100644 index 0000000..806bb2e --- /dev/null +++ b/Scripts/UnitySendMessageEventHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 651dc4d7dda3d4f7891de602a135a9e4 +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..1dd1ff0 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "xyz.candycoded.alertconfirmdialog", + "displayName": "Alert Confirm Dialog", + "version": "1.0.0", + "unity": "2019.2", + "unityRelease": "0f1", + "description": "Display simple alert and confirm dialogs on both iOS and Android.", + "license": "MIT", + "dependencies": { + "com.unity.modules.androidjni": "1.0.0" + }, + "keywords": [ + "ios", + "android", + "alert", + "confirm", + "dialog" + ], + "author": { + "name": "Scott Doxey", + "email": "hello@scottdoxey.com", + "homepage": "http://scottdoxey.com/" + }, + "homepage": "https://github.com/CandyCoded/AlertConfirmDialog", + "repository": { + "type": "git", + "url": "git@github.com:CandyCoded/AlertConfirmDialog.git" + } +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..4146e57 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 9b3eb19685cc3424ea37bada7c852fd6 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: