Unity3d calling third-party SDK (one) from Eclipse to Unity3d allies

Source: Internet
Author: User

Original address: http://www.360doc.com/content/14/0120/14/11670799_346638215.shtml

This article shows the implementation method of the Unity3d SDK.

First, attach the project source code address: Https://github.com/hiramtan/unity3d_test_umeng

Download and how to use the SDK see Official development document: Http://dev.umeng.com/doc/document_ana_android.html

Open Eclipse to create a new Android project:

Set up the package neme (Note: There is some information stating that the package name needs to be consistent with the bundle identifier inside the Unity3d.

But after testing, even if it is inconsistent, the function can still be realized ....

Find the SDK: you need to import Unity3d's own Classes.jar and Friends League SDK. First locate the Classes.jar in the Unity3d installation directory. The specific path is in this folder in your Unity3d's installation directory Editor\data\playbackengines\androidplayer\bin then is the Friend League SDK downloaded from the Internet.

Import the SDK in Eclipse by right-clicking the Eclipse project and selecting the last item:

After choosing Java build path, click Add External jars to find the Classes.jar and Friends League SDK mentioned above, respectively, and click OK, as follows:

After the import is successful, the following two items are added in eclipse:

Then you need to modify the Mainactivity.java as follows (there will be a complete code below):

Here Unity3d part of the work is completed, the following is the integration of the third-party SDK. The configuration information required by the SDK and the development documentation for the Logical Reference SDK website.

Here is the Friend League SDK, referring to the developer documentation of the Friends League SDK.

At this point we need to add an app to the Friend Alliance website, and the site will randomly assign a appkey. See official instructions on how to sign up for a friend Alliance service and how to add apps.

(If we need to add the Unicom paid SDK to the game, we certainly don't need to work with friends.) Instead, add apps to the Unicom developer site and get the app's built-in paid Appkey)

The application information I have added here is as follows, and here we need to know the Appkey assigned by the League of Friends. As follows:

Friends Alliance official Website Requirements Configuration Androidmanifest.xml as follows, specifically to see the official development of Friends League documents.

To do this, we configure Androidmanifest.xml in eclipse as follows (mainly by pasting the parts of the Allies request):

Modify the following:

[HTML]View Plaincopyprint?
  1. <? XML version= "1.0" encoding="Utf-8"?>
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  3. package="Com.example.test"
  4. android:versioncode="1"
  5. android:versionname="1.0" >
  6. <uses-sdk
  7. android:minsdkversion="8"
  8. android:targetsdkversion=" /> "
  9. <application
  10. android:allowbackup="true"
  11. android:icon="@drawable/ic_launcher"
  12. android:label="@string/app_name"
  13. android:theme="@style/apptheme" >
  14. <activity
  15. android:name="com.example.test.MainActivity"
  16. android:label="@string/app_name" >
  17. <intent-filter>
  18. <action android:name="Android.intent.action.MAIN" />
  19. <category android:name="Android.intent.category.LAUNCHER" />
  20. </intent-filter>
  21. </Activity>
  22. <meta-data android:value="523f9df156240b085a054288" android:name="Umeng_appkey " ></meta-data>
  23. <meta-data android:value="Channel ID" android:name="Umeng_channel"/>
  24. </Application>
  25. <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"></ uses-permission>
  26. <uses-permission android:name="Android.permission.INTERNET"></uses-permission >
  27. <uses-permission android:name="Android.permission.READ_PHONE_STATE"></ Uses-permission>
  28. </manifest>

Friends League Official Website request to add the import com.umeng.analytics.MobclickAgent, Friends of the Alliance official website requirements as follows:

Refer to the official Website development document to invoke the method encapsulated in the SDK, the final modification Mainactivity.java as follows:

[Java]View Plaincopyprint?
  1. Package com.example.test;
  2. Import Android.os.Bundle;
  3. Import android.app.Activity;
  4. Import Android.view.Menu;
  5. Import com.unity3d.player.UnityPlayerActivity; //unity3d
  6. Import com.umeng.analytics.MobclickAgent; //Friends League
  7. Public class Mainactivity extends Unityplayeractivity {
  8. @Override
  9. protected void OnCreate (Bundle savedinstancestate) {
  10. super.oncreate (savedinstancestate);
  11. //setcontentview (R.layout.activity_main);
  12. }
  13. @Override
  14. Public Boolean oncreateoptionsmenu (Menu menu) {
  15. //inflate the menu; This adds items to the action bar if it is present.
  16. Getmenuinflater (). Inflate (R.menu.main, menu);
  17. return true;
  18. }
  19. public void Onresume () {
  20. Super.onresume ();
  21. Mobclickagent.onresume (this);
  22. }
  23. public void OnPause () {
  24. Super.onpause ();
  25. Mobclickagent.onpause (this);
  26. }
  27. public void OnEvent ()
  28. {
  29. Mobclickagent.onevent (This, "testevent");
  30. System.out.println ("test");
  31. }
  32. }

Then export the jar package in eclipse to use in Unity3d, here is the export process, export/Select the export path, as follows:

The following directory is then created in Unity3d, where the Androidmanifest and res folders are copied from the Eclipse project (locate the project directory directly into the Unity3d directory).

The Bin folder and the Libs folder are created by yourself, where the bin folder puts the eclipse exported jar package, libs the third-party jar package. As follows:

Add code in Unity3d Test.cs to call the method created in Eclipse OnEvent ();

[CSharp]View Plaincopyprint?
  1. Using Unityengine;
  2. Using System.Collections;
  3. Public class Test:monobehaviour
  4. {
  5. Androidjavaclass Clas;
  6. Androidjavaobject obj;
  7. // Use this for initialization
  8. void Start ()
  9. {
  10. Clas = New Androidjavaclass ("Com.unity3d.player.UnityPlayer");
  11. obj = Clas.  Getstatic<androidjavaobject> ("currentactivity");
  12. }
  13. void Ongui ()
  14. {
  15. if (GUI.  button (new Rect (Screen.width * 0.3f, Screen.height * 0.3f, Screen.width * 0.3f, Screen.height * 0.3f), "click")
  16. Obj.  Call ("onEvent");
  17. }
  18. }

Here you can see the results:

1. After running the app click on Logcat as follows:

2. View custom events on your friends website:

You can see the statistics of custom events, indicating that the Unity3d SDK was successful. Invoking other SDK methods is the same.

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.