So I’ve got a script calling functions in native code, but I need to do the reverse. I’m wondering how to pass a callback function to native code that will get called when an event in native code occurs.
I’m talking about using the plug-in system in Unity iPhone Advanced.
you can not call unity from xcode, only vice versa.
Unity is not a framework to use within your app, it is the app and offers you now the capabilities to expand it with native functionality.
What I’m talking about is calling a callback function from Xcode.
For example: From Unity I call a native function that will take a few frames to provide results (because it retrieves data from the web). I’d like to register a C# function that can be called from native code when the results are ready.
The only other way to do this would to be have a native function that gets polled from C# to see if the results are ready, which isn’t as elegant.
It is definitely possible to pass function pointers from mono to native code, but I’m wondering if it can be done in Unity iPhone.
Your answer doesn’t contain any technical details about why it’s not possible, so I’m not sure if you understood what I’m asking.
If this isn’t possible with Unity iPhone, I’d like to request a UnitySendMessage() function that can be called from ObjC. This would basically be identical to the way the external SendMessage function works in the Unity Web Player.
That should not be no problem.
Send out the delegate to the function when you call the native function and the processing is done it calls that function again and thus should be able to inform unity of it.
But keep in mind that you will likely have some fun with marshaling and the InteropServices doing this.
Should, because that works with plugins in Unity Pro. I’ve not tested it on the iphone yet.
What I though see as a problem is that calls to plugin functions are blocking. so the function itself can not take several frames. Guess you have some kind of management framework around it that will have to store requests with callbacks / delegates.
I hope that helped
And sorry should the first answer have sounded harsh. Wasn’t its intend. Just attempted to plot the picture of how the technology is layed out in case you had a different picture of it. Saves you time thinking up ways that can not work due to the wrong picture of the whole situation.
Has anyone gotten the delegate callback to work? Or is anyone at least somewhat knowledgeable with respect to how to get a Mono delegate into Objective C?
I’m trying to enable menu functionality via a plugin, and everything works, up to the callback part. I’d rather not poll, if I can avoid it.