Unity calls Android platform Java code

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.