首页 > 代码库 > Unity与iOS原生代码之间的相互调用
Unity与iOS原生代码之间的相互调用
效果:
代码:
【GitHub】Unity_iOS_Plugin_Demo
关键:
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); } }
参考资料:
http://docs.unity3d.com/Manual/PluginsForIOS.html
https://github.com/asus4/UnityNativeDialogPlugin
http://blog.csdn.net/wwmusic/article/details/21008289
文档信息
- 原文网址:http://blog.csdn.net/cdztop/article/details/39805803
- 最后修改时间:2014年10月05日 20:58
Unity与iOS原生代码之间的相互调用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。