- Home /
Using AndroidJavaClass in a java Unity3d plugin
Hi, I'm working with a java plugin on Unity3d. In the java side, I have a static class:
public class MyClass{
public static void method1(){
}
public static void method2(){
}
public static void method3(){
}
}
This class is accessed from a c# script in Unity3d:
public class MyPlugin{
...
...
public void method1(){
if (Application.platform == RuntimePlatform.Android){
using (var pluginclass = new AndroidJavaClass("com.myapp.MyClass"))
{
if (pluginclass != null)
{
pluginclass .CallStatic("method1");
}
}
}
public void method2(){
if (Application.platform == RuntimePlatform.Android){
using (var pluginclass = new AndroidJavaClass("com.myapp.MyClass"))
{
if (pluginclass != null)
{
pluginclass .CallStatic("method2");
}
}
}
}
}
Well, my problem is that I want to know if is efficient call the java methods in that way or if I should use an attribute ( private AndroidJavaClass _androidclass) and instantiate only once.
The script is a singleton and is attached to a game object.
If you need more information, please let me know it. Thanks.
Your answer
Follow this Question
Related Questions
How can I know if I'm calling a plugin correctly? 0 Answers
Unity 5 seems to can't find my Android Plugin 0 Answers
How to merge multiple AndroidManifest.xml files?? 3 Answers
How do I override an Android Java class in Unity? 1 Answer
Did anyone built the Alembic Importer for Android and iOS? 0 Answers