本机Android应用程序(说NAA)
团结游戏(说UG)
我想将统一游戏(UG)集成到本机Android应用程序(NAA)
我将统一游戏导出到android中,该游戏转换为.aar库,并且能够将UG集成到NAA中。但是我想将统一游戏分数发送到本地android应用程序。
AndroidManagerScript。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AndroidManager : MonoBehaviour {
private AndroidJavaObject curActivity;
public string strLog = "No Java Log";
static AndroidManager _instance;
public Text _text;
public static AndroidManager GetInstance()
{
if( _instance == null )
{
_instance = new GameObject("AndroidManager").AddComponent<AndroidManager>();
}
return _instance;
}
void Awake()
{
#if UNITY_ANDROID
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
//AndroidJavaClass jc = new AndroidJavaClass("great.good.com.rolauncher");
curActivity = jc.GetStatic<AndroidJavaObject>("currentActivity");
#endif
_text = (Text)GameObject.Find ("Canvas/Text").GetComponent<Text>();
_text.text = strLog;
}
void Start ()
{
}
public void CallJavaFunc( string strFuncName, string strTemp )
{
if( curActivity == null )
{
strLog = curActivity + " is null";
return;
}
strLog = "Before call " + strFuncName;
//curActivity.Call(strFuncName, new object[] { strTemp } );
curActivity.Call( strFuncName, strTemp );
strLog = strFuncName + " is Called with param " + strTemp;
}
void SetJavaLog(string strJavaLog)
{
strLog = strJavaLog;
_text.text = strLog;
}
}
我在游戏退出时正在调用函数javaTestFunc
public void GQuit()
{
AndroidManager.GetInstance().CallJavaFunc( "javaTestFunc", "UnityJavaJarTest" );
Application.Quit();
}
本地Android代码
import com.Hash.FC.UnityPlayerActivity;
public class MainActivity extends com.unity3d.player.UnityPlayerActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (Button)findViewById(R.id.button);
Log.e("data","start");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, UnityPlayerActivity.class);
startActivity(i);
}
});
}
public void javaTestFunc(String strFromUnity) {
//java to unity
//UnityPlayer.UnitySendMessage("AndroidManager", "SetJavaLog", strFromUnity + "HelloWorld");
Log.e("data",strFromUnity);
}
public static void testMethod(){
Log.e("data","data");
}
}
JavaTestFunc没有触发。任何帮助将不胜感激。
答案 0 :(得分:0)
一个想法是只将数据保存在persistentDataPath中: https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
,然后从本机应用程序读取该文件夹。 我不确定这个限制,因为我只是将Unity3d与本机PC应用程序一起使用(我不确定是否可以读取android上的/ storage / emulated / 0 / Android / data // files的persistentDataPath另一个应用程序),但如果可能的话,您只需从本机应用程序中读取数据,然后从统一应用程序中写入数据。