参考文章均来源于【大神雨松momo】的文章。
unity -> iOS |
// unity 程序 usingSystem.Runtime.InteropServices; |
参考链接: |
// iOS 程序 @implementation TestView
void _PressButton111() { NSLog(@“unity里点击了按钮~~~"); } @end |
iOS -> unity |
// unity程序 cube111 上的任意?脚本 publicvoidMoveDown111(stringstr) |
参考链接: |
// iOS 程序 参数1:场景中的模型名称,Cube111就是我们定义的一个箱子。 参数2:脚本方法名称methodName111就是上面脚本中的方法, 参数3:为一个char *类型的可以向Unity中传递数据。
UnitySendMessage(“Cube111”,"methodName111","传给unity。。。"); |
|
|
|
|
unity -> android |
// unity 程序(cube111 上的任意?脚本) publicvoidCallAndroid(stringstr) |
// android 程序 publicvoidStartActivity0(Stringstr) { // 接收到 unity 传来的 str } |
|
android -> unity |
// unity 程序(Cube111上的脚本) public voidmethodName111(stringstr) { // 接收到 andorid 传来的 str } |
|
// android 程序 import com.unity3d.player.UnityPlayer; //参数1表示游戏对象的名称,参数2表示对象绑定的脚本接受该消息的方法名字,参数3表示本条消息发送的字符串信息,这个方法和IOS 发送的方式非常相像 UnityPlayer.UnitySendMessage(“Cube111”,”methodName111”,"传递给unity的数据");
|