码迷,mamicode.com
首页 > 移动开发 > 详细

Unity与iOS原生代码之间的相互调用

时间:2014-10-05 23:42:09      阅读:924      评论:0      收藏:0      [点我收藏+]

标签:unity   ios   互调   插件   陈小道   

效果:

bubuko.com,布布扣

代码:


关键:

1、Unity调用iOS:
1.1、在Unity C#中:
[ DllImport( "__Internal" )]
private static extern int _showSelectTitleDialog ( string title, string msg);

1.2、在Xcode Objective-C中:

extern "C" {
    int _showSelectTitleDialog(const char *title, const char *msg) {
        return [[UNDialogManager sharedManager]
                showSelectDialog:[NSString stringWithUTF8String:title]
                message:[NSString stringWithUTF8String:msg]];
    }
}

2、在iOS中调用Unity:
2.1、在Xcode Objective-C中:
UnitySendMessage("DialogManager", "OnCancel", tag.UTF8String);
2.2、在Unity C#中:
public void OnCancel ( string idStr)
{
        int id = int.Parse (idStr);
        if (_delegates.ContainsKey (id)) {
              _delegates [id] (-1);
              _delegates.Remove (id);
              Debug.LogWarning ( "===OnCancel idStr1:" + idStr);
       } else {
              Debug.LogWarning ( "===OnCancel idStr2:" + idStr);
       }
}

参考资料:




文档信息

  • 最后修改时间:2014年10月05日 20:58

Unity与iOS原生代码之间的相互调用

标签:unity   ios   互调   插件   陈小道   

原文地址:http://blog.csdn.net/cdztop/article/details/39805803

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!