Unity調用android平臺java代碼

最近由於公司須要開始研究Unity平臺的sdk接入。首先從調用最簡單的java代碼開始。html

1.首先創建android lib項目。java

package unityPlugin;

import com.unity3d.player.UnityPlayer;

import android.widget.Toast;

public class UnityPluginTest {
	public static void show(){
		UnityPlayer.currentActivity.runOnUiThread(new Runnable(){
			@Override
			public void run() {
				Toast.makeText(UnityPlayer.currentActivity, "調用成功", Toast.LENGTH_LONG).show();
			}
			
		});
	}
}

2. 包含有插件.class文件的.jar包。固然也能夠採用構建項目,而後取bin目錄下生成的jar包,試過這種方式也是可行的。android

 

 

3.將jar包放入到unity項目Assets->Plugins->Android文件夾ide

4.編寫調用java方法的代碼this

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	public void PrintTest(){
		var jo = new AndroidJavaObject ("unityPlugin.UnityPluginTest");
		jo.CallStatic("show");
	}
}

 

 

參考文章:http://game.ceeger.com/Manual/Plugins.htmlurl

     http://wenku.baidu.com/link?url=sDPRg0Fyqf-uadzbAPK4RhT_QwhHS_OyE-xebWr1NQ6_n5nV37fxnbWcwa27xxw7mwMaFstnSCzydc3SY7xfXiw5P48oYX7PgQSzYkUvOj3插件

   http://www.xuanyusong.com/archives/667/3d

相關文章
相關標籤/搜索