- Home /
plugins - handling native to C# code?
Hello,
I have a .so file I need to use on my android game. I have read http://unity3d.com/support/documentation/Manual/Plugins.html and it works fine when you invoke the native code with DLLimport.
The problem is that I also need to have the native code do callbacks into C# code, something the tutorial does not mention. How do you handle this the best way?
Answer by mdeletrain · Nov 21, 2011 at 12:04 PM
Looking at the 'Calling C# / JavaScript back from native code' paragraph, it seems Unity only supports native to C# messags on iOS devices.
My best bet is to open a socket on both sides to send text messages. This would reproduce what is supported on iOS devices but would make it usable on any platform.
Yep, it's propably easier but not that fast and will cause a delay. In this case it becomes an async-function. However it should be possible to call managed code from native code, but's it's always easier to break out of the managed environmenr than breaking in. See this article about native->managed. It's kinda mess and not explained very well but ir shows how it's done.
I never tried native to managed things in Unity, maybe it can't be done since Unity have some restrictions but it's worth a try.