如何在unity3d中实现亚马逊广告

14ifxucb  于 2023-03-19  发布在  其他
关注(0)|答案(1)|浏览(199)

我想添加亚马逊移动的广告到安卓和ios在unity3d游戏
面对这个代码中的问题

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;
}
nxagd54h

nxagd54h1#

在www.example.com上注册开发人员帐户developer.amazon.com
注册后,转到主 Jmeter 板页面,单击应用程序和服务选项卡,然后创建新应用程序
填写所有必要的信息并复制您的应用程序密钥x1c 0d1x
通过此链接下载亚马逊移动的广告SDK并导入广告插件
https://developer.amazon.com/public/resources/development-tools/sdk-thank-you?product=apps_games_services_unity
然后在Unity中添加此代码以初始化广告代码

  • “将以下代码放入脚本后,不要忘记将应用密钥粘贴到此脚本应用密钥参数内”*
using UnityEngine;

使用System.集合;使用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();
}

我的问题只是没有关系,因为我写这个教程,因为每个人都需要帮助,在这个主题
我希望这能帮上忙

相关问题