unity 3d与ios代码相互调用
来源:互联网 发布:查询数据库所有表 编辑:程序博客网 时间:2024/06/06 02:57
转自 http://blog.csdn.net/lanergaming/article/details/7566928
看unity3d两天了,一直想知道如何能让unity中添加ios的ui,苦于不知道两者直接如何相互调用,
今天查文档时发现其实不是很难。unity给出了相关的例子:Bonjour Browser Sample
1,Building an Application with a Native Plugin for iOS
- Define your extern method in the C# file as follows:
[DllImport ("__Internal")]private static extern float FooPluginFunction ();
- Set the editor to the iOS build target
- Add your native code source files to the generated XCode project's "Classes" folder (this folder is not overwritten when the project is updated, but don't forget to backup your native code).
If you are using C++ (.cpp) or Objective-C (.mm) to implement the plugin you must ensure the functions are declared with C linkage to avoid name mangling issues.
extern "C" { float FooPluginFunction ();}
Using Your Plugin from C#
iOS native plugins can be called only when deployed on the actual device, so it is recommended to wrap all native code methods with an additional C# code layer. This code should check Application.platform and call native methods only when the app is running on the device; dummy values can be returned when the app runs in the Editor. See the Bonjour browser sample application for an example.
2,Calling C# / JavaScript back from native code
Unity iOS supports limited native-to-managed callback functionality via UnitySendMessage:
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
This function has three parameters : the name of the target GameObject, the script method to call on that object and the message string to pass to the called method.
Known limitations:
- Only script methods that correspond to the following signature can be called from native code:
function MethodName(message:string)
- Calls to UnitySendMessage are asynchronous and have a delay of one frame.
- unity 3d与ios代码相互调用
- unity 3d与ios代码相互调用
- Unity调用Android与IOS平台代码
- unity与java相互调用
- Unity中JS与CS相互调用
- unity与android的相互调用
- unity中c#与java相互调用
- unity3d与ios相互调用
- Unity 与 iOS 间相互传消息
- Unity与iOS相互调起、交互
- Unity 3D 调用 Android
- Unity3D:unity与Android相互传递消息 & unity与ios相互传递消息
- JavaScript与Silverlight托管代码相互调用
- Android WebView与JavaScript代码相互调用
- C#代码与js的相互调用
- ios UIWebView 与JS相互调用
- IOS Object-C与Swift相互调用
- unity中c#与Objective-C相互调用
- android中一种欢迎界面模式
- 命令行中有空格不能执行
- Android 软件自动更新功能的实现
- Spring源码解析之:Spring Security启动细节和工作模式
- Django 1.5.4 专题18 User Profile
- unity 3d与ios代码相互调用
- 获取状态栏高度
- 实现抽屉方式的两种方法【未完成】
- 大厅里有100盏灯,每盏灯都编了号码,分别为1-100。每盏灯由一个开关来控制。
- linux之sed用法
- ffmpeg SDK开发手册
- Android 权限代码说明
- 2013-10-26笔记
- MAC下用XCode开发Cocoa程序简单教程