- Home /
unity plugins for mac,the bundle file how to callback the c#?
i build a plugins bundle for mac ,but i don't know how to callback c#? anyone know? thank you
c# calls into your bundle, not the other way round.
yes i know,like this:
[DllImport ("PluginName")]
private static extern float FooPluginFunction ();
c# calls into your bundle,it can work,but i want the code in the bundle can callback my c# code. how it do?
@Graham Dunnett: This is false, Unity does have official callback functionality.
The answer you shown is only for $$anonymous$$obile, desktop plugins doesn´t have this functionality. The only way on desktop you can do is creating a pool on the navitive code and call it frequently.
Answer by $$anonymous$$ · Dec 25, 2012 at 04:24 PM
I've been working with building plugins to Unity using Objective-C (To access parts of the Cocoa Touch framework which Unity does not have any prebuild solution to, such as the StoreKit framework for in app purchases).
If I understand your problem correctly, you wish to make some sort of call from Objective-C code (or C or C++) back into Unity? Preferably to some script attached to an object in the game, which is in most cases the only possible way.
If you have a look at the official Unity documentation for building plugins: Building plugins for iOS
You will see that they mention one official way of calling back to a script in Unity from native code, which is this function:
UnitySendMessage("GameObjectName1", "MethodName1", "Message to send");
This is, as far as I've ever found, the only official native-to-managed callback functionality which Unity supports. But from my experiences it is all you will ever need. It is also very easy to use.
This is the function you will call from your native code such as Objective-C, C, or C++, etc. The first parameter specifies the game object which contains a method you want to call from one of its attached scripts. The second parameter specifies the name of the method, and the last one is the parameter you want to give to the method.
This also means that any method in your Unity C# scripts you want to use as callback methods need a signature which is:
void (string)
That is, they must not return anything and they only have one parameter, namely of the type string.
But the documentation from the provided link covers all of this :)
Hope this helps!
Your answer
Follow this Question
Related Questions
Unity fails to include .bundle for native code plugin when building Intel Mac player. 0 Answers
Does Unity 5 support OSX i386 plugins (without x86_64)? 0 Answers
Why doesn't my bundle build for Mac OS X using Xcode 4.5? 1 Answer
What to choose to make .bundle plugin in XCode? 1 Answer
In-app purchase "Invalid product" on Mac Store build 0 Answers