One, Unity calls Object-c
A/C + + can interact directly with object-c, as long as the file suffix. m is changed directly to. mm and becomes a mixed file between C + + and object-c.
C # can also call C + + methods, so C # can interact with OBJECT-C.
Procedure: C # calls the C + + call Object-c
1.c/c++ Call Object-c
Create a new test.mm file that defines a C-style interface function. Such as:
test.mm
extern " C " { void Log (char* Arg) { // can call Object-c's function here //
such as [[Alertview alloc] init]; ...
}}
Place the test.mm file under the assets/plugins/iOS path for Unity project
2.c# Call C + +
New TestPluginiOS.cs, such as:
TestPluginiOS.cs
#ifUnity_ios &&! Unity_editor//compile only on iOS platformusingUnityengine;usingSystem.Collections;usingSystem;usingSystem.Runtime.InteropServices;//dllimport under this namespace Public classUniwebviewplugin {[DllImport ("__internal")] Private Static voidLog (stringArg); //1. Access rights are not necessarily private//2. Must be static//argument is string instead of char*}#endif
Note: The parameter is string instead of char*, and the relationship between C and C # parameter types is mapped http://blog.csdn.net/yatusiter/article/details/9221861
Second, object-c call C #
Use this method directly in object-c to call C # functions
Unitysendmessage ("GameObjectName1""MethodName1" " Message to send"); // parameter 1: Added the Gameobject name to invoke the function Script Component // parameter 2: Name of the callback function // Parameter 3: Parameters of the callback function
Like Java callback C # in Android development, three parameters are string types! But the third parameter in Android development cannot be null (if there are no arguments, you can use an empty string "", because using a null program will collapse)
Unity Object-c Interaction