Recently, the company needed to start researching SDK access to the Unity platform. Start by calling the simplest Java code first.
1. First build the Android Lib project.
Package Unityplugin;import Com.unity3d.player.unityplayer;import Android.widget.toast;public class UnityPluginTest { public static void Show () {UnityPlayer.currentActivity.runOnUiThread (new Runnable () {@Overridepublic void run () { Toast.maketext (unityplayer.currentactivity, "Call succeeded", Toast.length_long). Show ();}});}}
2. A. jar package containing the plugin. class file. Of course, it is also possible to build a project and then take the jar package generated in the bin directory, and try this way.
3. Put the jar package into the Unity Project Assets->plugins->android folder
4. Writing code that calls Java methods
Using unityengine;using System.collections;public class Test:monobehaviour {//Use the For Initializationvoid Start () {}//update is called once per framevoid update () {}public void Printtest () {var Jo = new Androidjavaobject ("Unityplugin. Unityplugintest "); Jo. Callstatic ("Show");}}
Reference article: http://game.ceeger.com/Manual/Plugins.html
Http://wenku.baidu.com/link?url=sDPRg0Fyqf-uadzbAPK4RhT_QwhHS_OyE-xebWr1NQ6_ N5nv37fxnbwcwa27xxw7mwmafstnsczydc3sy7xfxiw5p48oyx7pgqszykuvoj3
http://www.xuanyusong.com/archives/667/
Unity calls Android platform Java code