有米官網:http://www.youmi.net/register?r=MTI0MDg=javascript
國內的廣告,我以爲萬普和有米還不錯,我也只試了這兩個,其餘的都是看評價的,呵呵~~~首先咱們去有米官網註冊一個帳號http://www.youmi.net/register?r=MTI0MDg=;而後添加一個應用,添加成功後會給你一個ID和密鑰,在咱們的程序中會用到。html
在從官網下載jar包,目前有三個jar包,一個是廣告條的,另外一個是積分牆的,及推送廣告。還有就是導入unity的class.jar。java
其餘都就寫代碼啦,首先在eclipse下創建一個android工程,把下載的兩個jar包導入工程。咱們只須要寫他的主activity,AndroidManifest.xml和proguard-Projector.txt文件。android
MainActivity.java:web
注:注意把Activity改爲UnityPlayerActivity哦!app
- package com.dlnu.goddess;
-
- import com.unity3d.player.UnityPlayerActivity;
-
- import net.youmi.android.AdManager;
- import net.youmi.android.AdView;
- import net.youmi.android.appoffers.YoumiOffersManager;
- import net.youmi.android.appoffers.YoumiPointsManager;
- import net.youmi.push.android.YoumiPush;
- import android.os.Bundle;
- import android.content.Context;
- import android.view.ViewGroup.LayoutParams;
- import android.widget.LinearLayout;
-
- public class MainActivity extends UnityPlayerActivity {
-
- Context context =null;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- context = this;
- //推送廣告
- YoumiPush.startYoumiPush(this, "f6e5dc3a6da84ca0", "98fb0492fd253f61", true);
-
- //banner廣告
- AdManager.init(this,"9a96b4725e1947e6", "dbf605c63c57e21c", 30, false);
- LinearLayout layout=new LinearLayout(this);
- addContentView(layout, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
- AdView adView = new AdView(this);
- LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- layout.addView(adView, params);
-
- //積分牆
- YoumiOffersManager.init(this, "9a96b4725e1947e6", "dbf605c63c57e21c");
- }
- //打開積分牆
- void open1(){
- YoumiOffersManager.showOffers( MainActivity.this,YoumiOffersManager.TYPE_REWARD_OFFERS);
- }
- //打開推薦列表
- void opne2(){
-
- YoumiOffersManager.showOffers(MainActivity.this,YoumiOffersManager.TYPE_REWARDLESS_APPLIST);
-
- }
- //打開單個推薦
- void open3(){
-
- YoumiOffersManager.showOffers(MainActivity.this,YoumiOffersManager.TYPE_REWARDLESS_FEATUREDAPP);
- }
- //獲取積分
- int getpoint(){
-
- return YoumiPointsManager.queryPoints(this);
- }
-
- }
AndroidManifest.xml:eclipse
注:注意主Aactivity哦,我這裏是android:name="com.dlnu.goddess.MainActivity",就是咱們上面的那個Activity,其實就是你第一個看到的頁面,我的理解哦,呵呵~~~ide
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.dlnu.goddess"
- android:versionCode="1"
- android:versionName="1.0" >
-
- <uses-sdk
- android:minSdkVersion="8"
- android:targetSdkVersion="17" />
- <uses-permission android:name="android.permission.INTERNET"/>
- <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
- <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
- <uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name="com.dlnu.goddess.MainActivity"
- android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
-
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <service android:name="net.youmi.push.android.YoumiService"></service>
- <activity android:name="net.youmi.push.android.YoumiActivity"></activity>
- <receiver android:name="net.youmi.push.android.YoumiReceiver">
- <intent-filter>
- <action android:name="android.intent.action.BOOT_COMPLETED" />
- </intent-filter>
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED"/>
- <action android:name="android.intent.action.PACKAGE_INSTALL"/>
- <data android:scheme="package"/>
- </intent-filter>
- </receiver>
- <activity android:name="net.youmi.android.appoffers.YoumiOffersActivity"
- android:configChanges="keyboard|keyboardHidden|orientation"/>
- <activity
- android:configChanges="keyboard|keyboardHidden|orientation"
- android:name="net.youmi.android.AdActivity" />
- <receiver android:name="net.youmi.android.YoumiReceiver">
- <intent-filter>
- <action android:name="android.intent.action.PACKAGE_ADDED"/>
- <action android:name="android.intent.action.PACKAGE_INSTALL"/>
- <data android:scheme="package"/>
- </intent-filter>
- </receiver>
- <meta-data android:name="YOUMI_CHANNEL" android:value="0"></meta-data>
-
- </application>
-
- </manifest>
proguard-Projector.txt:函數
- # To enable ProGuard in your project, edit project.properties
- # to define the proguard.config property as described in that file.
- #
- # Add project specific ProGuard rules here.
- # By default, the flags in this file are appended to flags specified
- # in ${sdk.dir}/tools/proguard/proguard-android.txt
- # You can edit the include path and order by changing the ProGuard
- # include property in project.properties.
- #
- # For more details, see
- # http://developer.android.com/guide/developing/tools/proguard.html
-
- # Add any project specific keep options here:
-
- # If your project uses WebView with JS, uncomment the following
- # and specify the fully qualified class name to the JavaScript interface
- # class:
- #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
- # public *;
- #}
- -keep class net.youmi.push.android.** {
- *;
- }
- -keep class net.youmi.android.appoffers.** {
- *;
- }
- -keep class net.youmi.android.** {
- *;
- }
接下來的部分就得看雨鬆MOMO的了,先在unity下創建一個工程,安裝雨鬆momo的作法,把咱們android工程打包而且放入unity裏面就行,注意:在Plugins/Android/下要創建一個libs文件夾,把從有米官方下載的兩個jar包導入。Plugins/Android/libs/xxx.jar,yyy,jar;最後最重要的就是把工程的包名改爲android工程下的,我這裏是com.dlnu.nate;剩下的就是看你在unity下調用android裏面open1,open2,open3函數了。oop
Unity下的腳本:
- using UnityEngine;
- using System.Collections;
-
- public class AdTest : MonoBehaviour {
-
- AndroidJavaClass jc;
- AndroidJavaObject jo;
- void Start()
- {
- jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
- }
- void Update ()
- {
- if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home) )
- {
- Application.Quit();
- }
- }
-
- void OnGUI()
- {
- if(GUILayout.Button("OPEN1",GUILayout.Height(100)))
- {
- jo.Call("open1");
- }
- if(GUILayout.Button("OPEN2",GUILayout.Height(100)))
- {
- jo.Call("open2");
- }
- if(GUILayout.Button("OPEN3",GUILayout.Height(100)))
- {
- jo.Call("open3");
- }
- }
-
-
- }
注:必定要記得把報名改爲Android裏面的同樣哦!