自己在android写好方法,打包为AAR,在unity中调用此方法
java代码
public void ShowToast (final String msg)
{
runOnUiThread(new Runnable() {
@Override
public void run() {
//Toast.makeText(MainActivity.this,msg,Toast.LENGTH_LONG).show();
Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
});
}
unity打包Android工程失败(Unity与Android有交互的情况下),报错,请检查打包方式有没有更改。应该为Gradle
IOException: Failed to Copy File / Directory from 'Temp/StagingArea\android-libraries\toastlibrary-debug\classes.jar' to 'Temp/StagingArea\android-libraries\toastlibrary-debug\libs\classes.jar': destination path already exists.
C#中调用
AndroidJavaObject jo = new AndroidJavaClass("com.unity3d.player.UnityPlayer").GetStatic<AndroidJavaObject>("currentActivity");
jo.Call("ShowToast", "Hello");