Unity3D - 从 Android 调用静态方法
Unity3D - Call Static method from Android
我创建了用于从 Unity3D 打开 Android Activity 的简单插件。使用参数触发方法有问题。有什么想法吗?
Java代码
public static void Show(Activity activity, String value, String value2)
{
Intent myIntent = new Intent(activity, DisplayAllUnits.class);
myIntent.putExtra("key1",value);
myIntent.putExtra("key2",value2);
activity.startActivity(myIntent);
}
并在 onCreate
//load units for All Units placement from values
Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getString("key1");
value2 = extras.getString("key2");
}
a_id=value;
p_id=value2;
触发它的 C# 代码:
var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
var jc = new AndroidJavaClass("secret.package;)but.it.s.correct");
string value = "121";
string value2 = "1400";
jc.Call("Show", jo, "121", "1400");
什么是问题:
- 没有参数,工作,有参数我有以下错误:
I/Unity: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
您正在调用 Call
,这意味着调用实例方法。你想要 CallStatic
,它调用一个静态方法。
我创建了用于从 Unity3D 打开 Android Activity 的简单插件。使用参数触发方法有问题。有什么想法吗?
Java代码
public static void Show(Activity activity, String value, String value2)
{
Intent myIntent = new Intent(activity, DisplayAllUnits.class);
myIntent.putExtra("key1",value);
myIntent.putExtra("key2",value2);
activity.startActivity(myIntent);
}
并在 onCreate
//load units for All Units placement from values
Bundle extras = getIntent().getExtras();
if (extras != null) {
value = extras.getString("key1");
value2 = extras.getString("key2");
}
a_id=value;
p_id=value2;
触发它的 C# 代码:
var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var jo = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
var jc = new AndroidJavaClass("secret.package;)but.it.s.correct");
string value = "121";
string value2 = "1400";
jc.Call("Show", jo, "121", "1400");
什么是问题: - 没有参数,工作,有参数我有以下错误:
I/Unity: AndroidJavaException: java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
java.lang.NoSuchMethodError: no non-static method "Ldisplay/io/unity3dplugin/DisplayAllUnits;.Show(Lcom.unity3d.player.UnityPlayerActivity;Ljava/lang/String;Ljava/lang/String;)V"
您正在调用 Call
,这意味着调用实例方法。你想要 CallStatic
,它调用一个静态方法。