简体   繁体   中英

Passing IOS native objects back to unity3d

I implemented IOS plugin with couple of simple methods to interract my unity application with native static library.

The problem, I faced, is passing back native UI elements(objects) to unity.

Fe 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();    

and following:

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];

but inside unity.

I know there is ability to send message back to unity:

UnitySendMessage( "UnityCSharpClassName" , "UnityMethod", "WhateverValueToSendToUnity");

but WhateverValueToSendToUnity should be UTF8 string.

In conclusion:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM