using UnityEngine;
using System.Collections;
using UnityEngine.UI;
/// <summary>
/// 实现Unity所开发工程融入到Android工程并实现简单跳转功能
/// </summary>
public class Test : MonoBehaviour {
public Text my_test;
public void Input_Button()
{
AndroidJavaClass And_Class = new AndroidJavaClass("com.Coany.ProductName.UnityPlayerActivity");//"包名+主Activity"
var obj = And_Class.GetStatic<AndroidJavaObject>("currentActivity");
obj.Call("Test_1");//Android工程中的方法名
}
/*
* 注:
* 在Unity5.1.2中,"var obj = And_Class.GetStatic<AndroidJavaObject>("currentActivity");"中的"currentActivity"调试出错,
* 需要在Android工程中的UnityPlayerActivity类中添加:
*
* public static Activity currentActivity;
*
* 并在OnCreate()函数中初始化:
*
* currentActivity = this;
*
*
* 调用方法:
*
* public void Test_1() {
Log.d("abc", "test");
Intent intent = new Intent(UnityPlayerActivity.this,
MainActivity.class);
startActivity(intent);
}
*/
}
Unity 与 Android融合
最新推荐文章于 2020-06-20 11:00:28 发布