unity3d插入android有米广告

有米官网:http://www.youmi.net/register?r=MTI0MDg=

国内的广告,我觉得万普和有米还不错,我也只试了这两个,其他的都是看评价的,呵呵~~~首先我们去有米官网注册一个账号http://www.youmi.net/register?r=MTI0MDg=;然后添加一个应用,添加成功后会给你一个ID和密钥,在我们的程序中会用到。


在从官网下载jar包,目前有三个jar包,一个是广告条的,另一个是积分墙的,及推送广告。还有就是导入unity的class.jar。

unity3d插入android有米广告_第1张图片

其他都就写代码啦,首先在eclipse下建立一个android工程,把下载的两个jar包导入工程。我们只需要写他的主activity,AndroidManifest.xml和proguard-Projector.txt文件。

 

MainActivity.java:

注:注意把Activity改成UnityPlayerActivity哦!

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:

注:注意主Aactivity哦,我这里是android:name="com.dlnu.goddess.MainActivity",就是我们上面的那个Activity,其实就是你第一个看到的页面,个人理解哦,呵呵~~~




    
            
    
        
    
    
    
    
    
    
    
        
            
                

                
            
        
               
        
        
            
                
            
            
                
                
                
            
        
        
        
        
            
                
                
                
            
        
        
       
    


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函数了。

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("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里面的一样哦!


unity3d插入android有米广告_第2张图片

你可能感兴趣的:(Unity3D初步篇)