Beispiel #1
0
    public static AdConfig FromResponse(AdsServerResponse response, bool isTablet)
    {
        AdConfig adConfig = new AdConfig();

        if (!string.IsNullOrEmpty(response.adUnit_banner))
        {
            adConfig.bannerAdUnit = response.adUnit_banner;
        }
        else
        {
            adConfig.bannerAdUnit = ((!isTablet) ? "f22e60410d82403aa5e0fb791ef9c153" : "1253b5589a4d45869288611de14229d6");
        }
        if (!string.IsNullOrEmpty(response.adUnit_fullscreen))
        {
            adConfig.fsAdUnit = response.adUnit_fullscreen;
        }
        else
        {
            adConfig.fsAdUnit = ((!isTablet) ? "72bb0678c400487b8d1a941944fa6888" : "8cae328870984a9987623f9c6e52b25d");
        }
        if (!string.IsNullOrEmpty(response.adUnit_rewarded))
        {
            adConfig.rewardAdUnit = response.adUnit_rewarded;
        }
        else
        {
            adConfig.rewardAdUnit = ((!isTablet) ? "6bc3898062484e71a114d0ab59cb1c78" : "0543e571406140dd96252ac1351b99f5");
        }
        adConfig.adsDisabled        = (response.ad_module_active == 0);
        adConfig.interval           = response.interstitial_delay / 1000;
        adConfig.startInterval      = response.interstitial_delay_onstart / 1000;
        adConfig.appLaunchDelay     = (float)response.applaunch_delay / 1000f;
        adConfig.fsInternalOnReward = Mathf.Max(0, response.interstitial_delay_onreward / 1000);
        adConfig.bannerShowTime     = Mathf.Max(10, response.banner_show_time / 1000);
        adConfig.bannerLoadDelay    = Mathf.Max(1, response.banner_load_delay / 1000);
        adConfig.adsTest            = (response.ad_module_test_mode == 1);
        adConfig.placements         = new List <AdPlacement>();
        adConfig.chances            = new List <int>();
        if (response.fullscreen_showing_config != null)
        {
            for (int i = 0; i < response.fullscreen_showing_config.Length; i++)
            {
                AdsFsPlacementConfig adsFsPlacementConfig = response.fullscreen_showing_config[i];
                AdPlacement          adPlacement          = AdConfig.ParsePlacement(adsFsPlacementConfig.id);
                if (adPlacement != AdPlacement.Unknown)
                {
                    adConfig.placements.Add(adPlacement);
                    adConfig.chances.Add(Mathf.Clamp(adsFsPlacementConfig.chance, 0, 100));
                }
            }
        }
        if (response.banner_showing_config != null && response.banner_showing_config.id != null)
        {
            adConfig.bannerPos = AdConfig.ParseBannerPosition(response.banner_showing_config.show);
            if (adConfig.bannerPos != BannerPosition.None)
            {
                adConfig.bannerPlaces = new List <BannerPlacement>();
                for (int j = 0; j < response.banner_showing_config.id.Length; j++)
                {
                    BannerPlacement bannerPlacement = AdConfig.ParseBannerPlacement(response.banner_showing_config.id[j]);
                    if (bannerPlacement != BannerPlacement.Unknown)
                    {
                        adConfig.bannerPlaces.Add(bannerPlacement);
                    }
                }
            }
        }
        else
        {
            adConfig.bannerPos = BannerPosition.None;
        }
        adConfig.rewardConfig = AdConfig.FromRespone(response.rewarded_config, false);
        return(adConfig);
    }