Just a quick recap – we have created an Android module for displaying a native android alert dialog box in an android studio. Which we can call from our Unity3D project and when we will hit yes or no it will pass a message to unity3D on so that we can write our logic.
If you have not followed the last post of this series then Click Here.
In this post, we will see how to create Unity3D project through which we will invoke Alert Dialog Box via a native plugin that we had created in Part I of this post.
- Open Unity3D and create a new project – ‘AlertDialogBoxForAndroid‘.
And just like we did in Simple Android Plugin for Unity3D – Part 2.
- Open build settings of the project, and switch to android.
- Create a new folder – ‘Scene‘ and make an empty scene in that folder by Right Click > New> Scene. Name this scene as scene and add it in build settings.
- Create a new folder – ‘Scripts’ in asset folder.
- Create a new folder – ‘Plugins’ in asset folder.
- Create a new folder – ‘Android’ in Plugin folder created above.
- Create another new folder – ‘libs’ in android folder created above.
- Paste the classes.jar and AndroidManifest in the libs folder that we had created in part 1 of the post.
- In hierarchy Right Click > UI> Button, to create a button, and name it – ShowDialogBox
- In hierarchy Right Click > UI> Text, and name it – OutPut to create a label field that will display what button is pressed on the alert dialog box. Position them in whichever fashion that suits you.
- Create an empty GameObject in the hierarchy and name it – ‘Controller’. Create a new tag – ‘controller’ and attach it on the gameobject that we had created in this step.
- Create a new C# file name – ‘Controller.cs‘, in the scripts folder, attach this script on the gameobject – ‘Controller’ that we created in above step.
paste the below code in this class.
- Create another C# file name – ‘AndroidCallbacks.cs’ in scripts folder. And paste the below code in it
- Drop the script on the button, and add ShowNativeDialogBox() on the OnClick() of the button.
- Drop the OutPut(Text) we created above on the reply on the Controller.
- Build and run the project on your android device. Cheers!!
If you are curious and want to know about this project, then leave a comment or email me at email@example.com
If you are interested to know more about the work I have done than do the same as above 😀