【问题标题】:How to implement Amazon ads in unity3d如何在unity3d中实现亚马逊广告
【发布时间】:2016-08-11 07:13:19
【问题描述】:

我想在 unity3d 游戏中向 android 和 ios 添加亚马逊移动广告

并在这段代码中面临这个问题

public void createIad(){
    CreateInterstitialAd ();
}

Ad CreateInterstitialAd(){

IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
AdInterstitial = mobileAds.CreateInterstitialAd();
string adType = AdInterstitial.AdType.ToString();
long identifier = AdInterstitial.Identifier;
    /*
    LoadingStarted LSObject = mobileAds.LoadInterstitialAd();
    bool loadingStarted = LSObject.BooleanValue;
    */
    return AdInterstitial;
}

【问题讨论】:

    标签: unity3d amazon ads


    【解决方案1】:

    在 developer.amazon.com 上注册开发者帐户

    注册后转到主仪表板页面并单击“应用程序和服务”选项卡 并创建一个新的应用程序

    填写所有必要信息并复制您的应用程序密钥

    通过此链接下载亚马逊移动广告sdk并导入广告插件

    https://developer.amazon.com/public/resources/development-tools/sdk-thank-you?product=apps_games_services_unity

    然后在 Unity 中添加此代码以初始化您的广告代码

    “在您的脚本中放置以下代码后,不要忘记将您的应用密钥粘贴到此脚本应用密钥参数中”

    using UnityEngine;
    

    使用 System.Collections; 使用 com.amazon.mas.cpt.ads;

    public class AdTest : MonoBehaviour {
    
        public string androidKey;
    
        public string iosKey;
    
        private IAmazonMobileAds mobileAds;
    
        private static AdTest instance2;
    
        public static AdTest Instance
    
        {
            get { return instance2; }
        }
        void Awake() {
    
            DontDestroyOnLoad (transform.gameObject);
            // If no Player ever existed, we are it.
            if (instance2 == null)
                instance2 = this;
            // If one already exist, it's because it came from another level.
            else if (instance2 != this) {
                Destroy (gameObject);
                return;
            }
    
    
            //CloseFloatingAd ();
            //DisplayInterstitial ();
        }
    
    
        // Use this for initialization
        void Start () {
            SetAppKey ();
    
            //Delete this function before releasing your app
            EnableTesting ();
            //
    
            //DisplayInterstitial ();
    
        }
    
        // Update is called once per frame
        void Update () {
    
        }
    
    
        public void SetAppKey(){
    
            // Create a reference to the mobile ads instance
    
            mobileAds = AmazonMobileAdsImpl.Instance;
    
    
    
            // Create new key
    
            ApplicationKey key = new ApplicationKey ();
    
            //zum Testen
            //key.StringValue = androidKey;
    
            // Set key based on OS
    
            #if UNITY_ANDROID
    
            key.StringValue = androidKey;
    
            #elif UNITY_IPHONE
    
            key.StringValue = iosKey;
    
            #endif
    
    
    
            // Pass in the key
    
            mobileAds.SetApplicationKey (key);
    
        }
    
        public void EnableTesting(){
    
            //Create should enable instance
    
            ShouldEnable enable = new ShouldEnable ();
    
            enable.BooleanValue = true;
    
            mobileAds.EnableTesting (enable);
    
            mobileAds.EnableLogging (enable);   
    
        }
    
    
    
        Ad AdObject;
        /*
        public Ad CreateFloatingBannerAd(Placement input){
    
            IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
            Placement placement = new Placement ();
            placement.Dock = Dock.BOTTOM;
    
            placement.HorizontalAlign = HorizontalAlign.CENTER;
    
            placement.AdFit = AdFit.FIT_AD_SIZE;
    
            Ad response = mobileAds.CreateFloatingBannerAd (placement);
    
            string adType = response.AdType.ToString ();
            long identifier = response.Identifier;
    
        }*/
    
    
        public void CloseFloatingAd(){
    
            if (AdTest.Instance.AdObject != null) {
                IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
                mobileAds.CloseFloatingBannerAd (AdObject);
                CreateFloatingBannerAd ();
    
            }
        }
    
        LoadingStarted LoadInterstitialAd(){
            IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
            LoadingStarted response = mobileAds.LoadInterstitialAd ();
            bool loadingStarted = response.BooleanValue;
            return response;
        }
    
        public void createBanner(){
            CreateFloatingBannerAd ();
        }
    
    
        Ad CreateFloatingBannerAd(){
    
            // Configure placement for the ad
    
            Placement placement = new Placement ();
    
            //placement.Dock = Dock.TOP;
            placement.Dock = Dock.BOTTOM;
    
            placement.HorizontalAlign = HorizontalAlign.CENTER;
    
            placement.AdFit = AdFit.FIT_AD_SIZE;
    
            AdObject = mobileAds.CreateFloatingBannerAd(placement);
            return AdObject;
        }
    
        public void DisplayFloatingAd(){
    
            // Configure placement for the ad
    
            Placement placement = new Placement ();
    
            //placement.Dock = Dock.TOP;
            placement.Dock = Dock.BOTTOM;
    
            placement.HorizontalAlign = HorizontalAlign.CENTER;
    
            placement.AdFit = AdFit.FIT_AD_SIZE;
    
    
    
            // This method returns an Ad object, which you must save and keep track of
    
            AdObject = mobileAds.CreateFloatingBannerAd(placement);
    
    
    
            // This method returns a LoadingStarted object
    
            LoadingStarted newResponse = mobileAds.LoadAndShowFloatingBannerAd(AdObject);
    
        }
    
        Ad AdInterstitial;
        AdShown AdSObject;
    
        public void createIad(){
            CreateInterstitialAd ();
        }
    
        Ad CreateInterstitialAd(){
    
            Debug.Log ("CreateInterstitialAd()+++++++");
        IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
    
        AdInterstitial = mobileAds.CreateInterstitialAd();
    
        string adType = AdInterstitial.AdType.ToString();
        long identifier = AdInterstitial.Identifier;
            /*
            LoadingStarted LSObject = mobileAds.LoadInterstitialAd();
            bool loadingStarted = LSObject.BooleanValue;
            */
            return AdInterstitial;
        }
    
    
    
        public void DisplayInterstitial(){
    
            CreateInterstitialAd ();
    
            IAmazonMobileAds mobileAds = AmazonMobileAdsImpl.Instance;
    
            LoadingStarted LSObject = mobileAds.LoadInterstitialAd();
            bool loadingStarted = LSObject.BooleanValue;
    
    
                AdSObject = mobileAds.ShowInterstitialAd ();
                //bool adSwohn = AdSObject.BooleanValue;
    
    
        }
    
    
    }
    

    您还可以从此脚本调用实例来加载广告并显示它们 如下所示

    public void DisplayBanner () {
        AdTest.Instance.DisplayFloatingAd ();
    }
    public void CreateBanner () {
        AdTest.Instance.createBanner();
    }
    public void DisplayInterstitial () {
        AdTest.Instance.DisplayInterstitial();
    }
    public void CreateInterstitial () {
        AdTest.Instance.createIad();
    }
    

    我的问题并不重要,因为我写了这个教程是因为每个人都需要关于这个主题的帮助

    我希望这可能会有所帮助

    【讨论】:

      猜你喜欢
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多