├── .gitattributes ├── .gitignore ├── LICENSE ├── LICENSE.meta ├── README.md ├── README.md.meta ├── Runtime.meta ├── Runtime ├── Android.meta ├── Android │ ├── AndroidAlertDialog.cs │ └── AndroidAlertDialog.cs.meta ├── MS.NativeDialog.asmdef ├── MS.NativeDialog.asmdef.meta ├── NativeDialogManager.cs ├── NativeDialogManager.cs.meta ├── iOS.meta └── iOS │ ├── AlertDialogMessageReceiver.cs │ ├── AlertDialogMessageReceiver.cs.meta │ ├── UnityNativeDialogs.h │ ├── UnityNativeDialogs.h.meta │ ├── UnityNativeDialogs.mm │ ├── UnityNativeDialogs.mm.meta │ ├── iOSAlertDialog.cs │ └── iOSAlertDialog.cs.meta ├── package.json └── package.json.meta /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.DS_Store 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 zilch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c16e68d3d34b64be980cc18dfa52c8ed 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityNativeDialog 2 | Display native dialog in unity (support Android&iOS) 3 | 4 | # Import To Unity 5 | 6 | add to Packages/manifest.json: 7 | 8 | "com.ms.nativedialog":"https://github.com/wlgys8/UnityNativeDialog.git" 9 | 10 | # How to Use 11 | 12 | using MS.NativeDialog; 13 | .... 14 | 15 | //display dialog with one button 16 | NativeDialogManager.Display(new DialogDisplayOptions(){ 17 | title = title, 18 | message = message, 19 | positiveLabel = positiveLabel, 20 | onPositive = onPositive, //optional 21 | }); 22 | 23 | //display dialog with two button 24 | NativeDialogManager.Display(new DialogDisplayOptions(){ 25 | title = title, 26 | message = message, 27 | positiveLabel = positiveLabel, 28 | negativeLabel = negativeLabel, 29 | onPositive = onPositive, 30 | onNegative = onNegative, 31 | }); 32 | 33 | //display dialog with three button 34 | NativeDialogManager.Display(new DialogDisplayOptions(){ 35 | title = title, 36 | message = message, 37 | positiveLabel = positiveLabel, 38 | negativeLabel = negativeLabel, 39 | neutralLabel = neutralLabel, 40 | onPositive = onPositive, 41 | onNegative = onNegative, 42 | onNeutral = onNeutral, 43 | }); 44 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca6fc12b94e6e4bbba6335f3adf38f67 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 996fce14ffdcd40c981ad5b321fc4ffa 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Android.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e9672639f6364f209bd23b87713af0a 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/Android/AndroidAlertDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace MS.NativeDialog.Android 7 | { 8 | public class AlertDialog{ 9 | 10 | public const string JavaClickListener = "android.content.DialogInterface$OnClickListener"; 11 | public const string JavaDialogInterfaceName = "android.content.DialogInterface"; 12 | public const string JavaClassName = "android.app.AlertDialog"; 13 | private static AndroidJavaObject _activity; 14 | private static AndroidJavaObject activity{ 15 | get{ 16 | if(_activity == null){ 17 | using(var clazz = new AndroidJavaClass("com.unity3d.player.UnityPlayer")){ 18 | _activity = clazz.GetStatic("currentActivity"); 19 | } 20 | } 21 | return _activity; 22 | } 23 | } 24 | 25 | private static Dictionary _dialogs = new Dictionary(); 26 | 27 | private UnityAction _onDismiss; 28 | private AndroidJavaObject _jAlertDialog; 29 | public AlertDialog(AndroidJavaObject jAlertDialog){ 30 | _jAlertDialog = jAlertDialog; 31 | jAlertDialog.Call("setOnDismissListener",new OnDismissListener((jDialog)=>{ 32 | OnDismiss(); 33 | })); 34 | } 35 | 36 | private void OnDismiss(){ 37 | var hash = _jAlertDialog.Call("hashCode"); 38 | _dialogs.Remove(hash); 39 | if(_onDismiss != null){ 40 | _onDismiss(this); 41 | } 42 | } 43 | 44 | public void Dismiss(){ 45 | _jAlertDialog.Call("dismiss"); 46 | } 47 | 48 | public void SetCanceledOnTouchOutside(bool cancel){ 49 | _jAlertDialog.Call("setCanceledOnTouchOutside",cancel); 50 | } 51 | 52 | public void SetOnDismissListener(UnityAction onDismiss){ 53 | _onDismiss = onDismiss; 54 | } 55 | 56 | public class Builder{ 57 | 58 | private AndroidJavaObject _javaBuilder; 59 | public Builder(){ 60 | _javaBuilder = new AndroidJavaObject(JavaClassName + "$Builder",activity); 61 | } 62 | 63 | 64 | public Builder SetTitle(string title){ 65 | _javaBuilder.Call("setTitle",title); 66 | return this; 67 | } 68 | 69 | public Builder SetMessage(string message){ 70 | _javaBuilder.Call("setMessage",message); 71 | return this; 72 | } 73 | 74 | public Builder SetNegativeButton(string label,UnityAction listener){ 75 | _javaBuilder.Call("setNegativeButton",label,new OnClickListener((AndroidJavaObject rawDialog, int which)=>{ 76 | var hash = rawDialog.Call("hashCode"); 77 | var dialog = _dialogs[hash]; 78 | listener(dialog,which); 79 | })); 80 | return this; 81 | } 82 | 83 | public Builder SetPositiveButton(string label,UnityAction listener){ 84 | _javaBuilder.Call("setPositiveButton",label,new OnClickListener((AndroidJavaObject rawDialog, int which)=>{ 85 | var hash = rawDialog.Call("hashCode"); 86 | var dialog = _dialogs[hash]; 87 | listener(dialog,which); 88 | })); 89 | return this; 90 | } 91 | 92 | public Builder SetNeutralButton(string label,UnityAction listener){ 93 | _javaBuilder.Call("setNeutralButton",label,new OnClickListener((AndroidJavaObject rawDialog, int which)=>{ 94 | var hash = rawDialog.Call("hashCode"); 95 | var dialog = _dialogs[hash]; 96 | listener(dialog,which); 97 | })); 98 | return this; 99 | } 100 | 101 | public AlertDialog Show(){ 102 | var jAlertDialog = _javaBuilder.Call("show"); 103 | var dialog = new AlertDialog(jAlertDialog); 104 | int hash = jAlertDialog.Call("hashCode"); 105 | _dialogs.Add(hash,dialog); 106 | // Debug.LogFormat("AlertDialog Show ,hash = {0}",hash); 107 | return dialog; 108 | } 109 | } 110 | 111 | public class OnClickListener:AndroidJavaProxy{ 112 | 113 | private UnityAction _action; 114 | 115 | public OnClickListener(UnityAction action):base(JavaClickListener){ 116 | _action = action; 117 | } 118 | 119 | public void onClick(AndroidJavaObject dialog,int which){ 120 | _action(dialog,which); 121 | } 122 | } 123 | 124 | public class OnDismissListener:AndroidJavaProxy{ 125 | 126 | private UnityAction _onDismiss; 127 | public OnDismissListener(UnityAction action):base(JavaDialogInterfaceName + "$OnDismissListener"){ 128 | _onDismiss = action; 129 | } 130 | 131 | public void onDismiss(AndroidJavaObject dialog){ 132 | if(_onDismiss != null){ 133 | _onDismiss(dialog); 134 | } 135 | } 136 | } 137 | } 138 | 139 | } 140 | 141 | -------------------------------------------------------------------------------- /Runtime/Android/AndroidAlertDialog.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4f2197e3feb08428fb1526e53a3c1baa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/MS.NativeDialog.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MS.NativeDialog", 3 | "references": [], 4 | "optionalUnityReferences": [], 5 | "includePlatforms": [], 6 | "excludePlatforms": [], 7 | "allowUnsafeCode": false, 8 | "overrideReferences": false, 9 | "precompiledReferences": [], 10 | "autoReferenced": true, 11 | "defineConstraints": [] 12 | } -------------------------------------------------------------------------------- /Runtime/MS.NativeDialog.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 803eb7facfda54545a7bfaa798c051bf 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Runtime/NativeDialogManager.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Events; 5 | 6 | namespace MS.NativeDialog 7 | { 8 | public class DialogDisplayOptions{ 9 | public string title = "Default Title"; 10 | public string message = "Default Message"; 11 | 12 | public UnityAction onPositive; 13 | public UnityAction onNegative; 14 | public UnityAction onNeutral; 15 | 16 | public string negativeLabel; 17 | public string positiveLabel; 18 | public string neutralLabel; 19 | 20 | } 21 | public static class NativeDialogManager{ 22 | 23 | public static void Display(DialogDisplayOptions options){ 24 | List labels = new List(); 25 | List actions = new List(); 26 | 27 | var buttonCount = 0; 28 | 29 | if(!string.IsNullOrEmpty(options.positiveLabel)){ 30 | buttonCount ++; 31 | labels.Add(options.positiveLabel); 32 | actions.Add(options.onPositive); 33 | } 34 | if(!string.IsNullOrEmpty(options.negativeLabel)){ 35 | buttonCount ++; 36 | labels.Add(options.negativeLabel); 37 | actions.Add(options.onNegative); 38 | } 39 | 40 | if(!string.IsNullOrEmpty(options.neutralLabel)){ 41 | buttonCount ++; 42 | labels.Add(options.neutralLabel); 43 | actions.Add(options.onNeutral); 44 | } 45 | 46 | if(labels.Count == 0){ 47 | labels.Add("OK"); 48 | actions.Add(null); 49 | } 50 | #if UNITY_EDITOR 51 | bool res = false; 52 | if(labels.Count == 1){ 53 | res = UnityEditor.EditorUtility.DisplayDialog(options.title,options.message,labels[0]); 54 | if(res){ 55 | if(actions[0] != null){ 56 | actions[0](); 57 | } 58 | } 59 | }else if(buttonCount == 2){ 60 | res = UnityEditor.EditorUtility.DisplayDialog(options.title,options.message, 61 | labels[0],labels[1]); 62 | if(res){ 63 | if(actions[0] != null){ 64 | actions[0](); 65 | } 66 | }else{ 67 | if(actions[1] != null){ 68 | actions[1](); 69 | } 70 | } 71 | }else if(buttonCount == 3){ 72 | var which = UnityEditor.EditorUtility.DisplayDialogComplex(options.title,options.message, 73 | labels[0],labels[1],labels[2]); 74 | var actionIdx = which; 75 | if(actionIdx >= 0 && actionIdx < actions.Count){ 76 | if(actions[actionIdx] != null){ 77 | actions[actionIdx](); 78 | } 79 | } 80 | } 81 | 82 | #elif UNITY_ANDROID 83 | var builder = new Android.AlertDialog.Builder().SetTitle(options.title) 84 | .SetMessage(options.message); 85 | if(options.negativeLabel != null){ 86 | builder.SetNegativeButton(options.negativeLabel,(dialog,which)=>{ 87 | if(options.onNegative != null){ 88 | options.onNegative(); 89 | } 90 | }); 91 | } 92 | if(options.positiveLabel != null){ 93 | builder.SetPositiveButton(options.positiveLabel,(dialog,which)=>{ 94 | if(options.onPositive != null){ 95 | options.onPositive(); 96 | } 97 | }); 98 | } 99 | if(options.neutralLabel != null){ 100 | builder.SetNeutralButton(options.neutralLabel,(dialog,which)=>{ 101 | if(options.onNeutral != null){ 102 | options.onNeutral(); 103 | } 104 | }); 105 | } 106 | builder.Show(); 107 | #elif UNITY_IOS 108 | iOS.AlertDialog.Display(new iOS.AlertDialog.DisplayOptions(){ 109 | title = options.title, 110 | message = options.message, 111 | negativeButtonTitle = options.negativeLabel, 112 | positiveButtonTitle = options.positiveLabel, 113 | neutralButtonTitle = options.neutralLabel, 114 | onPositiveClick = options.onPositive, 115 | onNegativeClick = options.onNegative, 116 | onNeutralClick = options.onNeutral, 117 | }); 118 | #endif 119 | } 120 | } 121 | } 122 | 123 | -------------------------------------------------------------------------------- /Runtime/NativeDialogManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f34010813e4124ed3ac3901d698eada4 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d5e8f0ad6bd0c4813aecbec6395e05dd 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Runtime/iOS/AlertDialogMessageReceiver.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | #if UNITY_IOS 5 | 6 | namespace MS.NativeDialog.iOS 7 | { 8 | public class AlertDialogMessageReceiver : MonoBehaviour{ 9 | // Start is called before the first frame update 10 | 11 | public void OnUnityNativeDialogsAction(string message){ 12 | AlertDialog.ResolveAction(message); 13 | } 14 | 15 | [RuntimeInitializeOnLoadMethod] 16 | private static void Initialize(){ 17 | var receiver = new GameObject("_UnityNativeDialogs").AddComponent(); 18 | Object.DontDestroyOnLoad(receiver); 19 | } 20 | } 21 | } 22 | 23 | #endif 24 | 25 | 26 | -------------------------------------------------------------------------------- /Runtime/iOS/AlertDialogMessageReceiver.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d1ea8555a51c41c1bc6962e17444836 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Runtime/iOS/UnityNativeDialogs.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef UnityNativeDialogs_h 3 | #define UnityNativeDialogs_h 4 | 5 | #import 6 | @interface UnityNativeDialogs : NSObject {} 7 | 8 | + (int) displayAlertDialogWith: (const char*) title 9 | message:(const char*) message 10 | positiveButtonTitle:(const char*) positiveButtonTitle 11 | negativeButtonTitle:(const char*) negativeButtonTitle 12 | neutralButtonTitle:(const char*) neutralButtonTitle; 13 | @end 14 | 15 | #endif 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Runtime/iOS/UnityNativeDialogs.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 43a6bfd5c4503426894111520fcdca5a 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | '': Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 1 20 | Exclude Editor: 1 21 | Exclude Linux: 1 22 | Exclude Linux64: 1 23 | Exclude LinuxUniversal: 1 24 | Exclude OSXUniversal: 1 25 | Exclude Win: 1 26 | Exclude Win64: 1 27 | Exclude iOS: 0 28 | - first: 29 | Android: Android 30 | second: 31 | enabled: 0 32 | settings: 33 | CPU: ARMv7 34 | - first: 35 | Any: 36 | second: 37 | enabled: 0 38 | settings: {} 39 | - first: 40 | Editor: Editor 41 | second: 42 | enabled: 0 43 | settings: 44 | CPU: AnyCPU 45 | DefaultValueInitialized: true 46 | OS: AnyOS 47 | - first: 48 | Facebook: Win 49 | second: 50 | enabled: 0 51 | settings: 52 | CPU: AnyCPU 53 | - first: 54 | Facebook: Win64 55 | second: 56 | enabled: 0 57 | settings: 58 | CPU: AnyCPU 59 | - first: 60 | Standalone: Linux 61 | second: 62 | enabled: 0 63 | settings: 64 | CPU: x86 65 | - first: 66 | Standalone: Linux64 67 | second: 68 | enabled: 0 69 | settings: 70 | CPU: x86_64 71 | - first: 72 | Standalone: LinuxUniversal 73 | second: 74 | enabled: 0 75 | settings: 76 | CPU: None 77 | - first: 78 | Standalone: OSXUniversal 79 | second: 80 | enabled: 0 81 | settings: 82 | CPU: AnyCPU 83 | - first: 84 | Standalone: Win 85 | second: 86 | enabled: 0 87 | settings: 88 | CPU: AnyCPU 89 | - first: 90 | Standalone: Win64 91 | second: 92 | enabled: 0 93 | settings: 94 | CPU: AnyCPU 95 | - first: 96 | iPhone: iOS 97 | second: 98 | enabled: 1 99 | settings: 100 | AddToEmbeddedBinaries: false 101 | CompileFlags: 102 | FrameworkDependencies: 103 | userData: 104 | assetBundleName: 105 | assetBundleVariant: 106 | -------------------------------------------------------------------------------- /Runtime/iOS/UnityNativeDialogs.mm: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import "UnityNativeDialogs.h" 4 | #import "UnityInterface.h" 5 | 6 | extern void UnitySendMessage(const char *, const char *, const char *); 7 | 8 | extern "C"{ 9 | 10 | int UnityDisplayAlertDialog (const char* title,const char* message,const char* positiveButtonTitle,const char* negativeButtonTitle,const char* neutralButtonTitle){ 11 | return [UnityNativeDialogs displayAlertDialogWith:title message:message positiveButtonTitle:positiveButtonTitle 12 | negativeButtonTitle:negativeButtonTitle 13 | neutralButtonTitle:neutralButtonTitle]; 14 | } 15 | } 16 | 17 | 18 | @implementation UnityNativeDialogs 19 | 20 | + (int) displayAlertDialogWith: (const char*) title 21 | message:(const char*) message 22 | positiveButtonTitle:(const char*) positiveButtonTitle 23 | negativeButtonTitle:(const char*) negativeButtonTitle 24 | neutralButtonTitle:(const char*) neutralButtonTitle{ 25 | NSString* nsTitle = [NSString stringWithUTF8String:title]; 26 | NSString* nsMessage = [NSString stringWithUTF8String:message]; 27 | UIAlertController* alert = [UIAlertController alertControllerWithTitle:nsTitle message:nsMessage preferredStyle:UIAlertControllerStyleAlert]; 28 | 29 | if(positiveButtonTitle){ 30 | NSString* buttonTitle = [NSString stringWithUTF8String:positiveButtonTitle]; 31 | UIAlertAction *actionOther = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 32 | //Default Action 33 | UnitySendMessage("_UnityNativeDialogs", "OnUnityNativeDialogsAction", "Positive"); 34 | }]; 35 | [alert addAction:actionOther]; 36 | } 37 | 38 | if(negativeButtonTitle){ 39 | NSString* buttonTitle = [NSString stringWithUTF8String:negativeButtonTitle]; 40 | UIAlertAction *actionNegative = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { 41 | //Cancel Action 42 | UnitySendMessage("_UnityNativeDialogs", "OnUnityNativeDialogsAction", "Negative"); 43 | }]; 44 | [alert addAction:actionNegative]; 45 | } 46 | 47 | if(neutralButtonTitle){ 48 | NSString* buttonTitle = [NSString stringWithUTF8String:neutralButtonTitle]; 49 | UIAlertAction *actionOther = [UIAlertAction actionWithTitle:buttonTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 50 | //Default Action 51 | UnitySendMessage("_UnityNativeDialogs", "OnUnityNativeDialogsAction", "Neutral"); 52 | }]; 53 | [alert addAction:actionOther]; 54 | } 55 | [UnityGetGLViewController() presentViewController:alert animated:TRUE completion:nil]; 56 | return 0; 57 | } 58 | @end 59 | 60 | -------------------------------------------------------------------------------- /Runtime/iOS/UnityNativeDialogs.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 79182b2859ee5421381cfde7f09d1718 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 0 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | iPhone: iOS 27 | second: 28 | enabled: 1 29 | settings: {} 30 | - first: 31 | tvOS: tvOS 32 | second: 33 | enabled: 1 34 | settings: {} 35 | userData: 36 | assetBundleName: 37 | assetBundleVariant: 38 | -------------------------------------------------------------------------------- /Runtime/iOS/iOSAlertDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using System.Runtime.InteropServices; 5 | using UnityEngine.Events; 6 | 7 | #if UNITY_IOS 8 | 9 | namespace MS.NativeDialog.iOS 10 | { 11 | public static class AlertExternMethods{ 12 | 13 | [DllImport("__Internal")] 14 | public static extern int UnityDisplayAlertDialog(string title,string message, 15 | string positiveButtonTitle,string negativeButtonTitle,string neutralButtonTitle); 16 | } 17 | public class AlertDialog{ 18 | 19 | private static DisplayOptions _currentOptions; 20 | public static void Display(DisplayOptions options){ 21 | _currentOptions = options; 22 | AlertExternMethods.UnityDisplayAlertDialog(options.title,options.message, 23 | options.positiveButtonTitle,options.negativeButtonTitle,options.neutralButtonTitle); 24 | } 25 | 26 | public static void ResolveAction(string actionName){ 27 | if(actionName == "Negative"){ 28 | if(_currentOptions != null && _currentOptions.onNegativeClick != null){ 29 | _currentOptions.onNegativeClick(); 30 | } 31 | }else if(actionName == "Positive"){ 32 | if(_currentOptions != null && _currentOptions.onPositiveClick != null){ 33 | _currentOptions.onPositiveClick(); 34 | } 35 | }else if(actionName == "Neutral"){ 36 | if(_currentOptions != null && _currentOptions.onNeutralClick != null){ 37 | _currentOptions.onNeutralClick(); 38 | } 39 | } 40 | _currentOptions = null; 41 | } 42 | 43 | public class DisplayOptions{ 44 | public string title; 45 | public string message; 46 | public string negativeButtonTitle; 47 | public string positiveButtonTitle; 48 | public string neutralButtonTitle; 49 | 50 | public UnityAction onNegativeClick; 51 | public UnityAction onPositiveClick; 52 | public UnityAction onNeutralClick; 53 | 54 | } 55 | 56 | } 57 | } 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /Runtime/iOS/iOSAlertDialog.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37e5a10fcaf364281b52a255826a1abe 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.ms.nativedialog", 3 | "displayName": "Native Dialog", 4 | "version": "0.0.2", 5 | "description": "Native Dialog for Unity. Support Android&iOS", 6 | "keywords": [ 7 | "dialog","native" 8 | ] 9 | } 10 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58948f97b11b546388298e91a044d491 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------