- Home /
How to implement an Adnroid plugin with events
Hi, I use some Bluetooth Android plugin. It consist from "bluetooth.jar" library and two C# scripts: the first one just calls methods from library, the second script contains callback methods for android events. For example:
public class BluetoothEventListener : MonoBehaviour {
void FoundDeviceEvent(string Device)
{
//todo
}
}
Could anybody explain to me how it's work? In other words, how call from java code some methods in Unity's script (C# or JavaScript)?
http://docs.unity3d.com/$$anonymous$$anual/PluginsForAndroid.html
You have some example on how to make communication between Unity and android. Is that what you mean?
I know how to call external methods from Unity, but I don't know How to do the reverse operation? Or how to subscribe to android events?
I mean. I want to create Android plugin for Unity with events.
I don't understand how the plugin contains two C# scripts. Are you sure they are C#? maybe they are java scripts. The whole question would make more sense if they are Java scripts. But then, you provide an example of the 2nd script to be a $$anonymous$$onoBehaviour... Please clarify.
EDIT: corrected typo
Sorry for the misunderstanding. Since you said that you wanted to call Unity C# from Java, I mistakenly thought that the Bluetooth scripts were also possibly in Java. Apparently, you want to call from another Java (3rd) script, from outside of Unity, the methods in the 2nd C# script of the plugin inside Unity.
So, now I can provide an answer.
Answer by pako · Dec 18, 2014 at 03:49 PM
Use the UnityPlayer.UnitySendMessage method as described in the notes below the code of Example 3:
http://docs.unity3d.com/Manual/PluginsForAndroid.html
...and detailed in the iOS implementation:
fafase and pako, thank you both! I have read this manual before but not enough carefully.
Your answer
Follow this Question
Related Questions
OpenFeint Achievement Implementation 1 Answer
plugins - handling native to C# code? 1 Answer
Android, FMod and Unity 0 Answers
How to pass an interface to Java from Unity code? 2 Answers
android: why scene goes black when showing new activity? 3 Answers