用户工具

站点工具


侧边栏



Unity3D中文文档

script:unityengine:classes:androidjavaproxy:androidjavaproxy

AndroidJavaProxy 安卓Java代理

Description 描述

This class can be used to implement any java interface. Any java vm method invocation matching the interface on the proxy object will automatically be passed to the c# implementation.

这个类可以用来实现任何Java接口。任何Java虚拟机调用代理对象上匹配的接口将自动传递到C #实现。

JavaScript:

未提供代码

C#:

// Opens an android date picker dialog and grabs the result using a callback.
private static DateTime selectedDate = DateTime.Now;
class DateCallback : AndroidJavaProxy
{
	public DateCallback() : base("android.app.DatePickerDialog$OnDateSetListener") { }
	void onDateSet(AndroidJavaObject view, int year, int monthOfYear, int dayOfMonth)
	{
		selectedDate = new DateTime(year, monthOfYear+1, dayOfMonth);
	}
}
void OnGUI ()
{
	if (GUI.Button(new Rect (15, 15, 450, 75), string.Format("{0:yyyy-MM-dd}", selectedDate)))
	{
		var activity = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
		activity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
		{
			new AndroidJavaObject("android.app.DatePickerDialog", activity, new DateCallback(), selectedDate.Year, selectedDate.Month-1, selectedDate.Day).Call("show");
		}));
	}
}

Variables 变量

javaInterfaceJava interface implemented by the proxy.
由代理实现的javaInterface Java接口。

Constructors 构造函数

Functions 函数

InvokeCalled by the java vm whenever a method is invoked on the java proxy interface. You can override this to run special code on method invokation, or you can leave the implementation as is, and leave the default behavior which is to look for c# methods matching the signature of the java method.
每当一个方法在Java代理接口由Java虚拟机被调用时,你可以重写该方法来运行特定代码,或者你可以保留默认行为,这将查找C#方法中与Java签名相匹配的方法。
script/unityengine/classes/androidjavaproxy/androidjavaproxy.txt · 最后更改: 2016/08/02 05:33 (外部编辑)