New Android project in 1.eclipse, add Mainactivity.java code:
Packagecom.example.test;ImportCom.unity3d.player.UnityPlayer;Importcom.unity3d.player.UnityPlayerActivity;ImportAndroid.os.Bundle; Public classMainactivityextendsunityplayeractivity {protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); } Public voidSend () {Unityplayer.unitysendmessage ("AAA", "Androidcallback", "Okokoko"); }}
mainactivity
Export the jar package from eclipse
2.Unity, New project,
Write the EclipseCall.cs code as follows:
using unityengine;using system.collections;using unityengine.ui;using System; Public classeclipsecall:monobehaviour{PrivateAndroidjavaclass JC; PrivateAndroidjavaobject Jo; Privatetext text; PrivateButton btn; //single-case mode Private StaticEclipsecall _instance; Public StaticEclipsecall Instance {get {if(_instance = =NULL) {_instance=NewEclipsecall (); } return_instance; } } voidStart () {text= Gameobject.find ("AAA"). Getcomponent<text>(); BTN= Gameobject.find ("button"). Getcomponent<button>(); This. Name = "AAA"; _instance= This; JC=NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"); Jo= JC. Getstatic<androidjavaobject> ("CurrentActivity"); } Public voidclickbtn () {Jo. Call ("Send"); } Public voidandroidcallback (String str) {Text.text=str; }}
Eclipsecall
Drag the exported jar package from eclipse into the Libs file
Packaged:
Run, click the UI after:
Unity's SDK access (Unity and Android communication)