Hi all,
I have been working with Unity using plugin for a while. It works perfect when I use the plugin APIs inside the script. However, I was wondering is there any method to work in the opposite way? Let’s say I would like to notify Unity3D when something is happened in the plugin side. Is there any function call to do so?
No, there is no callback system.
I’m not sure the full performance implications of this and it’s an untested idea but…
You could have a script that does a if (System.IO.File.Exists(“someFile.txt”))in it’s update loop. The plugin can write out an enum value to this file if it wants to flag Unity to perform some acition. If the file exists; read that value, take the action and delete the file.
It’s not particularly speedy, so depending on what you want the callbacks to handle you may want to check only every few frames or so for the file. But since the iPhone is all solid state storage it shouldn’t be too bad?
before you waste time on a file based system, you would use the PlayerPrefs way.
But I’m actually not sure if you could not just hand out a delegate to the plugin end and call it as function pointer there. Though you would have to ensure that the delegate called does not use unity functionality as unity is not threadsafe (yes I know, the iphones right now are single core but its a matter of time likely next year until its no longer and you don’t want your apps to just crash on those do you)
I researched passing function pointers from Mono to ObjC, and it doesn’t work with AOT (ahead of time) compiled stuff in the version of Mono that Unity iPhone is using.
MonoTouch has a way to do it, but I couldn’t find a way to do it in Unity iPhone.
So just passing out a delegate doesn’t work?
Well was just an idea that might have worked but it seems like the mono 1.x based deploy with AoT UT has created doesn’t feature it then …