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?
- <? XML version= "1.0" encoding="Utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="Com.example.test"
- android:versioncode="1"
- android:versionname="1.0" >
- <uses-sdk
- android:minsdkversion="8"
- android:targetsdkversion=" /> "
- <application
- android:allowbackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/apptheme" >
- <activity
- android:name="com.example.test.MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="Android.intent.action.MAIN" />
- <category android:name="Android.intent.category.LAUNCHER" />
- </intent-filter>
- </Activity>
- <meta-data android:value="523f9df156240b085a054288" android:name="Umeng_appkey " ></meta-data>
- <meta-data android:value="Channel ID" android:name="Umeng_channel"/>
- </Application>
- <uses-permission android:name="Android.permission.ACCESS_NETWORK_STATE"></ uses-permission>
- <uses-permission android:name="Android.permission.INTERNET"></uses-permission >
- <uses-permission android:name="Android.permission.READ_PHONE_STATE"></ Uses-permission>
- </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?
- Package com.example.test;
- Import Android.os.Bundle;
- Import android.app.Activity;
- Import Android.view.Menu;
- Import com.unity3d.player.UnityPlayerActivity; //unity3d
- Import com.umeng.analytics.MobclickAgent; //Friends League
- Public class Mainactivity extends Unityplayeractivity {
- @Override
- protected void OnCreate (Bundle savedinstancestate) {
- super.oncreate (savedinstancestate);
- //setcontentview (R.layout.activity_main);
- }
- @Override
- Public Boolean oncreateoptionsmenu (Menu menu) {
- //inflate the menu; This adds items to the action bar if it is present.
- Getmenuinflater (). Inflate (R.menu.main, menu);
- return true;
- }
- public void Onresume () {
- Super.onresume ();
- Mobclickagent.onresume (this);
- }
- public void OnPause () {
- Super.onpause ();
- Mobclickagent.onpause (this);
- }
- public void OnEvent ()
- {
- Mobclickagent.onevent (This, "testevent");
- System.out.println ("test");
- }
- }
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?
- Using Unityengine;
- Using System.Collections;
- Public class Test:monobehaviour
- {
- Androidjavaclass Clas;
- Androidjavaobject obj;
- // Use this for initialization
- void Start ()
- {
- Clas = New Androidjavaclass ("Com.unity3d.player.UnityPlayer");
- obj = Clas. Getstatic<androidjavaobject> ("currentactivity");
- }
- void Ongui ()
- {
- if (GUI. button (new Rect (Screen.width * 0.3f, Screen.height * 0.3f, Screen.width * 0.3f, Screen.height * 0.3f), "click")
- Obj. Call ("onEvent");
- }
- }
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.