- Home /
Is there any method to callback from plugin (Windows)?
Hi there,
This is on Windows
I want to integrate a library into Unity. This library can receive some events. I want to pass these events into Unity. Can I call C# functions from C just like C's callback functions? Is using UnitySendMessage the only way to send back messages into Unity? If so, can UnitySendMessage be used in Windows? Thanks.
just FWIW you may like to look at the prime1 page (they are the leaders in Unity plugin technology!) You'll see from their docs how to use delegates, etc.
Answer by hs · Jan 04, 2013 at 11:44 AM
I find the answer from Unity Forum. http://forum.unity3d.com/threads/89930-Communicating-C-with-C
Answer by $$anonymous$$ · Dec 26, 2012 at 02:38 PM
I just recently answered the same question which can be found here: relevant answer
I think that's exactly what you are looking for :) It's all I've had a need for when developing plugins, and as Fattie said, I, too looked at the prime1 documentation to see how they implemented it on the Unity script side, and it's all entirely possible with the use of UnitySendMessage.
That's quite pointless. Beside the fact that the iOS version of the unity engine provides the UnitySend$$anonymous$$essage function (which actually works similar to Send$$anonymous$$essage in the web player object), as far as I know it's not available for windows. Since iOS uses xcode it was quite simple to add this function to their engine. On all other platforms the unity engine was never ment to be used from external applications / plugins.
Next point is that UnitySend$$anonymous$$essage has quit an overhead since it has to find the game object first. It also delays each callback one frame. Since Unity uses a single thread for scripting and made the API not thread safe it's pointless to use callbacks. Your plugin either provides instant result by returning something to the caller, or you have to poll your plugin every frame.
Prime31 mainly develops for $$anonymous$$ac and iOS. I haven't seen any evidence that UnitySend$$anonymous$$essage will work on Android. On Android there are other alternatives, but the question here was about a windows build.
Sorry, but my tablet don't know "xcode" :D That auto-correction is annoying sometimes... I fixed it :)
Ah - interestingly, when you edited that, it did NOT send a new copy (well not to me anyway). Previously, if one edited a typo in a comment, it would somewhat annoyingly send the new version to everyone. Perhaps they've made a change. Cheers
(We live in the age of "annoying autocorrection" :) )
Hi All,
Actually, I have read Unity manual about "Plugins (Pro/$$anonymous$$obile-Only Feature)", "Building Plugins for Desktop Platforms", "Building Plugins for iOS", and "Building Plugins for Android". I know I can use UnitySend$$anonymous$$essage for iOS plugin, but I cannot find the same method for windows plugin (as Bunny83 mentioned).
According to your previous discussions, it seems C# delegate is a possible solution. Can anyone give me some examples or links? Especially, how to pass C# delegate into C API in Unity?
Thanks.