2. androidStudio calls Unity method

1. Import Unity's Classes.jar file

(1), first find where this package is

When the Unity version is before 5.0, the path of classes.jar: classes.jar under
the installation path of
Unity \ Editor \ Data \ PlaybackEngines \ androidplayer \ bin The path of classes.jar when Unity version is 5.0 and after:
the installation of Unity Path \ Editor \ Data \ PlaybackEngines \ AndroidPlayer \ Variations \ mono
\ Release \ Classes

From-Link: https://www.jianshu.com/p/b059e84e85d1

(2), after finding it, copy it to the AndroidStudio app-> libs directory

(3) Right-click on the package after copying and click Add As Library

(4) After clicking, he will be configured to the build.gradle file

2. Reference package in code

(1) After you add As LIbrary, you can open this package-you can see the specific content of this package

(2), I paste the code below

package imsdk.u3d.unitytoandroid;

import com.unity3d.player.UnityPlayer;//引用 (也可以先不写  写下面的UnityPlay他自动会出来) 

public class Test {

    public void sendMessageToUnity(){
        //UnityPlayer.UnitySendMessage("物体的名字","方法名","参数");//这个方法 大家可以去自行查一下Unity官方文档
        UnityPlayer.UnitySendMessage("Canvas","AndroidCallBack","随便传个都行 需要Json的话就穿Json需要什么传什么");
    }
 }


Mine is the script mounted on Canvas so I wrote Canvas on it and there is an AndroidCallBack method in the script so the method name above is AndroidCallBack

3. Then type the jar package as I wrote last time

Guess you like

Origin www.cnblogs.com/Aaron-Han/p/12752030.html