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