unity 3d与ios代码相互调用
来源:互联网 发布:太空堡垒网络剧抵抗 编辑:程序博客网 时间:2024/06/06 10:53
看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相互调用
- 【练习】输入一颗二元树,从上往下按层打印树的每个结点,同一层中按照从左往右的顺序打印
- poj 1095 二叉树的编号
- android NDK
- VC删除IE缓存、COOKIE及记录
- HDU 2544 最短路 dijkstra floyd
- unity 3d与ios代码相互调用
- 一个对象使用instanceof 和getClass的区别
- Python语言中的关键字及操作格式符整理
- AMSDK Linux User's Guide
- java 给图片加文字
- fstab
- 2006年百度之星程序设计大赛初赛题目1:饭团的烦恼
- 面向接口编程详解(一)——思想基础
- yii 分页显示列表内容.