Unity3d game engine: unity3d feedback to iOS Advanced Interface (10)

Source: Internet
Author: User

Unity3d game engine: unity3d feedback to iOS advanced interface message

If the original Yusong Momo article is reprinted, please note: Reprinted to my independent domain name blog Yusong Momo program Research Institute, Original address: http://www.xuanyusong.com/archives/521



The previous chapter introduced the process of sending messages to unity3d and receiving messages from unity3d on the IOS advanced interface. The process of sending messages to unity3d is perfect, in this chapter, Momo introduces unity3d message feedback.


As shown in, in this chapter, we aim to add two GUI buttons on the unity3d interface, and click these two buttons on the iPhone to bring up the two advanced IOS interfaces. I believe that you should be familiar with the GUI. Here, I will call the GUI as a set of UI systems provided by unity3d. The two UI buttons in the figure are made using the GUI.








Create a C # script in the project column named main. cs. I have never used C # To write a script. Today I use C # To write this script ~~~ Drag the script to the camera, as shown in. The script declares two texture variables to save the image resources drawn by the button.







Main. CS code


Using unityengine; using system. collections; public class main: monobehaviour {// declare two texture variables. The image resource value is public texture button0; Public texture button1; // use this for initializationvoid start () {} // update is called once per framevoid Update () {} // This method is used to draw void ongui () {// draw two buttons if (GUI. button (New rect (120,120,), button0) {// If the returned value is true, this button is clicked SDK. activatebutton0 ();} // draw two buttons if (GUI. button (New rect (120,120,), button1) {// If the returned value is true, this button is clicked SDK. activatebutton1 ();}}}

The SDK class is described in detail here. This class is considered as a management class. It is not assigned to any object and only accepts call management, after clicking the two buttons, The _ activatebutton0 () and _ activatebutton1 () methods in the following method are called respectively. The two methods call xcode's own method _ pressbutton0 () with _ pressbutton1 (), you must register in the following code. In this way, xcode will generate registration information when exporting the project. We only need to implement these two methods.




SDK. CS code

Using unityengine; using system. runtime. interopservices; public class SDK {// after the export button, the registration of this button will be generated in the xcode project. // You can implement the event after this button is clicked in the xocde code. [Dllimport ("_ internal")] Private Static extern void _ pressbutton0 (); public static void activatebutton0 () {If (application. platform! = Runtimeplatform. osxeditor) {// click the button to call the _ pressbutton0 () method in xcode. You must add _ pressbutton0 ();} in the // method ();}} // same as [dllimport ("_ internal")] Private Static extern void _ pressbutton1 (); public static void activatebutton1 () {If (application. platform! = Runtimeplatform. osxeditor) {_ pressbutton1 ();}}}


In this way, the unity3d part has been completed. Export the untiy3d project to the xcode project and use xcode to open it. Add a response event after clicking the GUI button in unit3d. Create a class named myview. h. myview. m, which is used to receive unity3d feedback messages. The _ pressbutton0 and _ pressbutton1 methods have been registered in unity3d, therefore, we need to implement it in xcode in this class.


Myview. m

# Import "myview. H "@ implementation myview // receives the message void _ pressbutton0 () {uialertview * Alert = [[uialertview alloc] init]; [alert settitle: @ "Yusong Momo Program World"]; [alert setmessage: @ "click the first button"]; [alert addbuttonwithtitle: @ "OK"]; [alert show]; [alert release];} void _ pressbutton1 () {uialertview * Alert = [[uialertview alloc] init]; [alert settitle: @ "Yusong Momo Program World"]; [alert setmessage: @ "click the second button"]; [alert addbuttonwithtitle: @ "OK"]; [alert show]; [alert release];} @ end

Okay. Now, we can connect to the real machine to run our project. After clicking the unity3d GUI button in the iPhone, the dialog box on the IOS advanced interface is displayed through message feedback ~






Finally, you are welcome to discuss unity3d game development with Momo. In the winter, you should pay attention to clothes and health. Wow ~~~ Attached to the unity3d project, I will not upload the xcode project and export it by myself. It's not too early. Good night, everyone ~~

: Http://www.xuanyusong.com/archives/521


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.