Unity and Android Coordination work considerations

Source: Internet
Author: User
Tags function prototype

Original address: http://blog.csdn.net/u012085988/article/details/17436191

1. Unity Tune Android function

[CSharp]View Plaincopy
    1. Androidjavaclass JC = new Androidjavaclass ("Com.unity3d.player.UnityPlayer");
    2. Androidjavaobject activity = JC.  Getstatic<androidjavaobject> ("currentactivity");
    3. Activity. Call ("func")

Activity is the current Activity,call function prototype call<re-type> (FName, args). Within the angle brackets is the return value, the first argument is the function name, the second is the argument

Note: The number of arguments

1, the number is the same, and more than 1. Executable

2. Unity brings in fewer parameters than Android defines. Error: Nosuchmethoderror

3. Unity brings in more parameters than the number of Android-defined parameters. Error: Nosuchmethoderror

Note: When the Android side has overloaded functions

According to the parameter table, find the corresponding function

Note: The JNI is based on similar (ljava/lang/string; Ljava/lang/string;i) v This format to match the function. So the number of parameters, parameter type must be one by one corresponding

2. Android Callback Unity function

[CSharp]View Plaincopy
    1. Unityplayer.unitysendmessage ("Androidmanager", "Androidcallbackunlockgame", " " ");

The first argument is Gameobject, the second argument is the function name, and the third is the argument (string)

Note: The names are case-sensitive. and the parameter type, the number of parameters should be corresponding to each.

Note: The third argument cannot be null, to pass an empty string, you can write "", but you cannot write null. Otherwise it will crash!

3. UI processing in Android

[CSharp]View Plaincopy
    1. Runonuithread (new Runnable () {
    2. public Void Run () {
    3. Text (msg);
    4. }
    5. });

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.