Unity and iOS interaction

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/alongu3d/p/3674174.html

Environment: Mac os 10.9.2 Unity 4.2.1f4 Xcode 5.0.2

Unity iOS interaction I wrote a tutorial, I used Unity4.0, and now the version is not the same!

Link is http://www.cnblogs.com/alongu3d/p/3279277.html

1. First define the following in Unity's script

Where Callu3d is a static method for Unity3d calls!

2. Export iOS Project

The method we defined in Unity3d just now Callios, there will be Callios () in RegisterMonoModules.cpp in the project directory of iOS!

If this does not show the method we defined in Unity3d, then it is likely that this is the wrong one [DllImport ("__internal")] Note is two underscores

Let's take a closer look at the above sentence of the Callios () Method! Target_iphone_simulator non-emulator, must be running under the real machine in order to invoke the custom write method in iOS!

3. Implementing the Callios Method

extern "C" {    //when clicking the button in unity, this method is called, and a form    void    Callios () is popped up ()    {        customviewcontroller* myview= [[Customviewcontroller alloc]init];        [_maindisplay->window  AddSubview:myview.view];}    }

This method I wrote in the Unityappcontroller.mm method, _maindisplay->window is static, you can add a view here!

How to call iOS in 4.unity

-(Ibaction) Clickbutton: (ID) sender{    //Parameter 1 in Unity in the hierarchy list object parameter 2 cube object on the Rot method  parameter 3 is the parameter    unitysendmessage ("Cube", "Rot", "");}

When you click on a button on the view to send a message to unity, the first parameter is the object in the hierarchy view in unity, and the second parameter is the script that is carried by the object in the hierarchy view in unity.

Rot method, the third parameter is the parameters of the rot Method!

5. Next article about how to use the iOS account to publish the real machine and test!

Unity and iOS interaction

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.