Unity Integrated Unicom SDK

Source: Internet
Author: User
Tags android games

I believe that unity programmers will encounter the issue of joining the SDK, I believe if you do not Android programming, I believe your CPU on the spot calculation too fast and explode! I'm writing a note here to help you.

If there is a wrong place, I hope you can reply and provide answers! Let's work together against the SDK hehe

Pre-Knowledge:

1. Unity Access SDK comes in two ways:

The first: Eclipse writes plug-ins into unity, and Unity writes the code to publish the game directly (the first way to use the plate face with good luck)

The second: Unity first write code-"Android Project-" Eclipse SDK Access-"Use Eclipse release SDK

2. Unity calls Java Write method: (note is not very write, I do not understand Android programming)

//Get the Unity System classAndroidjavaclass JC =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer");//This should be getting the current pageAndroidjavaobject activity = JC. Getstatic<androidjavaobject> ("currentactivity");//Call order static method, pass four parameters [current page, billing number, callback Unity's game object name, callback Unity's method name]Activity. Callstatic ("Order",New Object[] {activity,"001","Cube","Bakcground"});

3. How Android calls Unity to write

// [Game Object name, method name, passed parameters] Unityplayer.unitysendmessage (gameobject,runtimescript,arg1+"");

Precautions: (Unicom SDK)

1. You write a good program released APK, the cause of the direct crash on the phone:

1. Unity Bundle Identifier (the main entry package xxx.xxx.xxx you created the Android project) does not match

2. Your Android plugin put in Unity ' when the location error: (First, according to the Unicom SDK copy, you find that the less xxx, I can only hehe)

3. Unicom SDK Call, if you write a method, directly call Pay () Pop-up Payment interface (direct program crashes), you do not have to know how to die!

Utils.getinstances (). Pay (context mcontext,string number, Unipayresultlistener listener); Today asked the next to sit my brother opposite, =. = He tells me what child thread is calling the UI error. Then I have always guessed what was wrong ....

Unity 3D mobile Game development PDF Author: Jinxi Once (in the release of Android games how to access the SDK to speak very detailed) code written in eclipse:

Package COM.EXAMPLE.HELLOWORLDSDK; This must correspond to the Unity ID corresponding to the import Android.os.bundle;import android.os.handler;import android.os.message;import Android.content.context;import Com.unicom.dcloader.utils;import Com.unicom.dcloader.utils.unipaypayresultlistener;import Com.unity3d.player.unityplayer;import com.unity3d.player.UnityPlayerActivity; Public classMainactivity extends Unityplayeractivity {Privatecontext Context; PrivateString Gameobject; PrivateString Runtimescript; PrivateUnipaypayresultlistenerimp imp =NewUnipaypayresultlistenerimp (); PrivateUnipayhandler handler =NewUnipayhandler ();  Public Staticmainactivity _instance; @Overrideprotected voidonCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); //Initializing the SDKUtils.getinstances (). INITSDK (mainactivity. This,0); _instance= This; }             Public Static voidOrder (Context _context,string number,string gameobject,string runtimescript) {_instance.paypage (_context, numb    Er, gameobject, runtimescript); }        //Call Payment Page     Public voidpaypage (Context _context,string number,string gameobject,string runtimescript) { This. Context =_context;  This. Gameobject =Gameobject;  This. Runtimescript =Runtimescript; 
//Use Handler to invoke pay to correctly eject the payment interface Message msg=NewMessage (); Msg.obj=Number ;    Handler.sendmessage (msg); }        classUnipayhandler extends Handler { Public voidhandlemessage (Message message) {utils.getinstances (). Pay (context, (String) message.obj,imp); }    }        classUnipaypayresultlistenerimp implements Unipaypayresultlistener {@Override Public voidPayresult (String arg0,intarg1, String arg2) {            //[Game Object name, method name, passed parameters]Unityplayer.unitysendmessage (gameobject,runtimescript,arg1+""); }            }    }

Code in Unity:

usingUnityengine;usingSystem.Collections;usingSystem; Public classTest:monobehaviour {Private stringerror; voidOngui () {if(GUI. Button (NewRect (0,0, -, -),"Payment Page"))        {            Try             {                                //Get the Unity System classAndroidjavaclass JC =NewAndroidjavaclass ("Com.unity3d.player.UnityPlayer"); //This should be getting the current pageAndroidjavaobject activity = JC. Getstatic<androidjavaobject> ("currentactivity"); //Call order static method, pass four parameters [current page, billing number, callback Unity's game object name, pay callback Unity's method name]Activity. Callstatic ("Order",New Object[] {activity,"001","Cube","Bakcground" }); }Catch(Exception e) {error+=E.message; }} GUI. Label (NewRect (0, -, -, -), error); }     Public voidBakcground (stringresult) {Error+="Callback succeeded:"+result; }    }

To access the SDK steps:

1. Create a new Android project

2. Import Classes.jar (Unity this you can check under that folder)

3. Copy all of the Libs under Libs under Eclipse

4. Modify Androidmanifest.xml

5. Write the code that was called by unity, export the jar package to the entire project, and put it under the Plugins/android file

6. Copy the Eclipse Libs folder to the Plugins/android file

7. Copy the Androidmanifest.xml to the Plugins/android file

8. Unzip the Multimode_unipay_base.jar and Multimode_unipay_extend.jar package, and under the current folder, copy only the assets folder to the Plugins/android file.

9. Write the code and publish the APK directly using unity

Information on Unity and Android communication:

http://blog.csdn.net/xv_ly15/article/details/9314199 Unity calls Android function

http://blog.csdn.net/richway2010/article/details/6640837 Eclipse Real-Machine debugging

I wish you a happy life! Plate face

Unity Integrated Unicom SDK

Related Article

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.