将IOS本机对象传递回unity3d [英] Passing IOS native objects back to unity3d
问题描述
我用几种简单的方法实现了IOS插件,以使我的统一应用程序与本地静态库相互干扰.
I implemented IOS plugin with couple of simple methods to interract my unity application with native static library.
我面临的问题是将本机UI元素(对象)传回统一.
The problem, I faced, is passing back native UI elements(objects) to unity.
F.e本机SDK具有创建徽章(UIView)的方法,另一方面,我具有统一的按钮(可以是GUI元素或某些3d对象,无论如何)
F.e native SDK has method that creates badge (UIView), on the other hand I have button in unity (it could be GUI element or some 3d object, whatever)
我可以通过插件通过统一方式访问此方法,例如:
I access this method from unity through my plugin, smth like:
[DllImport("__Internal")]
private static extern void XcodePlugin_GetBadgeView();
及以下:
void XcodePlugin_GetBadgeView()
{
// Generate native UIView
UIView *badge = [Badge badge];
???? Return UIView badge instance to unity (hm)?!
}
所以我需要类似的东西:
So I need something like:
[someViewOrObject addSubView:badge];
但内在统一.
我知道有能力将信息发送回团结:
I know there is ability to send message back to unity:
UnitySendMessage( "UnityCSharpClassName" , "UnityMethod", "WhateverValueToSendToUnity");
但是WhateverValueToSendToUnity应该是UTF8字符串.
but WhateverValueToSendToUnity should be UTF8 string.
结论:
只有一个主意,我必须将坐标从unity传递到本机插件,然后将徽章添加到这些坐标(不确定这是最好的解决方案):
Only one idea I have to pass coordinates from unity to native plugin, and then add badge to these coordinates(not sure this is best solution):
[DllImport("__Internal")]
private static extern void XcodePlugin_AddBadgeViewToCoordinates(x,y);
推荐答案
如果仅用于徽章坐标,则您的想法似乎很好.
If it's just for the badge coordinates, your idea seems fine.
如果您想将其他东西从iOS移植到Unity中,我认为没有其他选择.我唯一想到的另一种方法是将数据保存在文件中(例如,在NSTemporaryDirectory中),然后使用UnitySendMessage将文件名作为UTF8String传递回去.我之前曾使用过这种技术(将图像和JSON文件传递给Unity). iOS中会自动清理该目录中的文件.
If there are other things you'd like to get from iOS into Unity, I don't think there are many other options. The only other way that I can think of is to save the data in a file (eg, in NSTemporaryDirectory) and then pass the filename back as a UTF8String using UnitySendMessage. I've used this technique before (to pass images and JSON files) to Unity. Files in that directory get cleaned up automatically by iOS.
这篇关于将IOS本机对象传递回unity3d的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!