安卓部分代码:

public class GameMainActivity extends UnityPlayerActivity {

    private static String CODE_ROOT = "CodeRoot";

    public void initIAP() {
        UnityPlayer.UnitySendMessage(CODE_ROOT, "LogToUnity", "Call Init IPA Complete");
    }
}

CodeRoot是挂在接收Message的GameObject路径

Unity部分代码:

public void OnClickBtn1(){
    AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
    AndroidJavaObject curActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");

    //以上两步取得了Activity, 然后Call 就可以调用
    curActivity.Call("initIAP");
}
04-14 08:56