Esempio n. 1
0
 private void HandleReward(AdPlacementType type)
 {
     if (IsTimerRunning(type))
     {
         ResetTimer(type);
     }
 }
Esempio n. 2
0
    IEnumerator CoShowBanner(AdPlacementType placementType = AdPlacementType.Banner, BoolDelegate onAdLoaded = null)
    {
        bool isSuccess = false;
        WaitForSecondsRealtime checkInterval = new WaitForSecondsRealtime(0.3f);

        var adPriority = GetAdsNetworkPriority(placementType);

        for (int i = 0; i < adPriority.Count; i++)
        {
            bool checkAdNetworkDone = false;
            var  adsHelper          = GetAdsNetworkHelper(adPriority[i]);
            if (adsHelper == null)
            {
                continue;
            }
            adsHelper.ShowBanner(placementType,
                                 (success) => { checkAdNetworkDone = true; isSuccess = success; onAdLoaded?.Invoke(success); });
            while (!checkAdNetworkDone)
            {
                yield return(checkInterval);
            }
            if (isSuccess)
            {
                //showingBanners.Add(CurrentAdNetwork);
                isShowingBanner = true;
                break;
            }
        }
    }
Esempio n. 3
0
    public void ShowBanner(AdPlacementType placementType = AdPlacementType.Banner, BoolDelegate onAdLoaded = null)
    {
        if (isShowingBanner)
        {
            Debug.Log("AdsManager: A banner is already being shown"); return;
        }
        if (DoNotShowAds(placementType))
        {
            onAdLoaded?.Invoke(false);
            return;
        }
        ;
        StartCoroutine(CoShowBanner(placementType, onAdLoaded));

        /*switch (CurrentAdNetwork)
         * {
         *  case CustomMediation.AD_NETWORK.Unity:
         *      UnityAdsManager.ShowBanner(CustomMediation.GetUnityPlacementId(placementType));
         *      break;
         *  case CustomMediation.AD_NETWORK.FAN:
         *      FacebookAudienceNetworkHelper.instance.ShowBanner(CustomMediation.GetFANPlacementId(placementType));
         *      break;
         * }
         * showingBanners.Add(CurrentAdNetwork);*/
    }
Esempio n. 4
0
 public void StopTimer(AdPlacementType placementType)
 {
     if (_timers.ContainsKey(placementType))
     {
         _timers[placementType].Pause();
     }
 }
Esempio n. 5
0
 public void ResetTimer(AdPlacementType placementType)
 {
     if (_timers.ContainsKey(placementType))
     {
         RaiseTimerComplete(placementType);
     }
 }
Esempio n. 6
0
    public void RequestInterstitialNoShow(AdPlacementType placementType, InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        //if (DoNotShowAds(placementType) || !HasEnoughTimeBetweenInterstitial()) //skip checking interstitial time so we can use this function for preloading interstitial ads
        if (DoNotShowAds(placementType))
        {
            onAdLoaded?.Invoke(false);
            return;
        }
        if (isLoadingInterstitial)
        {
            Debug.LogWarning("Previous interstitial request is still loading");
            onAdLoaded?.Invoke(false); //added this so game can continue even with interstitial not finished loading
            return;
        }
        if (showLoading)
        {
            Manager.LoadingAnimation(true);
        }
        StartCoroutine(CoRequestInterstitialNoShow(placementType, onAdLoaded, showLoading));
        timeLastShowInterstitial = time;

        /*switch (CurrentAdNetwork)
         * {
         *  case CustomMediation.AD_NETWORK.Unity:
         *      UnityAdsManager.instance.RequestInterstitialNoShow(CustomMediation.GetUnityPlacementId(placementType), onAdLoaded, showLoading);
         *      break;
         *  case CustomMediation.AD_NETWORK.FAN:
         *      FacebookAudienceNetworkHelper.instance.RequestInterstitialNoShow(CustomMediation.GetFANPlacementId(placementType), onAdLoaded, showLoading);
         *      break;
         * }*/
    }
Esempio n. 7
0
 public AdMobLocation admobGetPlacementType(AdPlacementType bannerType)
 {
     if (bannerType == AdPlacementType.BottomLeft)
     {
         return(AdMobLocation.BottomLeft);
     }
     else if (bannerType == AdPlacementType.BottomCenter)
     {
         return(AdMobLocation.BottomCenter);
     }
     else if (bannerType == AdPlacementType.BottomRight)
     {
         return(AdMobLocation.BottomRight);
     }
     else if (bannerType == AdPlacementType.TopLeft)
     {
         return(AdMobLocation.TopLeft);
     }
     else if (bannerType == AdPlacementType.TopRight)
     {
         return(AdMobLocation.TopRight);
     }
     else if (bannerType == AdPlacementType.TopLeft)
     {
         return(AdMobLocation.TopLeft);
     }
     else if (bannerType == AdPlacementType.Centered)
     {
         return(AdMobLocation.Centered);
     }
     else
     {
         return(AdMobLocation.TopCenter);
     }
 }
Esempio n. 8
0
    IEnumerator CoReward(BoolDelegate onFinish, AdPlacementType placementType)
    {
        RewardResult           rewardResult = new RewardResult(); string errorMsg = string.Empty;
        WaitForSecondsRealtime checkInterval = new WaitForSecondsRealtime(0.3f);

        List <CustomMediation.AD_NETWORK> adPriority = GetAdsNetworkPriority(placementType);

        for (int i = 0; i < adPriority.Count; i++)
        {
            bool checkAdNetworkDone     = false;
            IAdsNetworkHelper adsHelper = GetAdsNetworkHelper(adPriority[i]);
            if (adsHelper == null)
            {
                continue;
            }
            adsHelper.Reward(placementType, (result) =>
            {
                checkAdNetworkDone = true; rewardResult = result;
            });
            while (!checkAdNetworkDone)
            {
                yield return(checkInterval);
            }
            if (rewardResult.type == RewardResult.Type.Finished)
            {
                currentAdsHelper = adsHelper;
                break;
            }
            if (rewardResult.type == RewardResult.Type.Canceled)
            {
                break;
            }                                                               //if a reward ads was shown and user skipped it, stop looking for more ads
        }

        /*for (int i = 0; i < adsNetworkHelpers.Count; i++)
         * {
         *  bool checkAdNetworkDone = false;
         *  adsNetworkHelpers[i].Reward(placementType, (result) =>
         *  {
         *      checkAdNetworkDone = true; rewardResult = result;
         *  });
         *  while (!checkAdNetworkDone)
         *  {
         *      yield return checkInterval;
         *  }
         *  if (rewardResult.type == RewardResult.Type.Finished)
         *  {
         *      currentAdsHelper = adsNetworkHelpers[i];
         *      break;
         *  }
         *  if (rewardResult.type == RewardResult.Type.Canceled) { break; } //if a reward ads was shown and user skipped it, stop looking for more ads
         * }*/
        onFinish(rewardResult.type == RewardResult.Type.Finished);
        Manager.LoadingAnimation(false);
        if (rewardResult.type == RewardResult.Type.LoadFailed)
        {
            ShowError(rewardResult.message, placementType);
        }
    }
Esempio n. 9
0
        private void SetCooldown(AdPlacementType placementType)
        {
            var activeAdInfo = _adInfo.GetActiveAd(placementType);

            _cooldownAds.Add(placementType, activeAdInfo);
            if (_cooldownCoroutine == null)
            {
                _cooldownCoroutine = StartCoroutine(WaitForCoolDown());
            }
        }
    List <CustomMediation.AD_NETWORK> GetAdsNetworkPriority(AdPlacementType placementType)
    {
        var config = GetPlacementConfigData(placementType);

        if (config != null)
        {
            return(config.GetAdNetworkPriority());
        }
        return(null);
    }
    RemoteConfigAdsPlacementData GetPlacementConfigData(AdPlacementType placementType)
    {
        string key = ((int)placementType).ToString();

        if (configData != null && configData.ContainsKey(key))
        {
            return(configData[key]);
        }
        Debug.LogError($"Config for placement {placementType} not found");
        return(null);
    }
Esempio n. 12
0
        private void RaiseTimerComplete(AdPlacementType placementType)
        {
            var now      = TimeUtil.UtcTimeInSecondsSinceEpoch();
            var activeAd = _adInfo.GetActiveAd(placementType);

            activeAd.CooldownTime     = now;
            activeAd.AvailabilityTime = now + _adPlacements[placementType].CoolDownTime;
            _adInfo.ReplaceActiveAd(activeAd);
            OnTimerComplete.Invoke(placementType);
            _timers.Remove(placementType);
            SetCooldown(placementType);
        }
Esempio n. 13
0
        public AdStateItem GetStateItem(AdPlacementType type)
        {
            var item = AllAdStateItems.Where(y => y.AdType == type).SingleOrDefault();

            if (item == null)
            {
                item = new AdStateItem(type);
                AllAdStateItems.Add(item);
            }

            return(item);
        }
    bool CheckHideAds(AdPlacementType placementType)
    {
        /*configData = new Dictionary<string, RemoteConfigAdsData>() {
         *   {"1", new RemoteConfigAdsData()},
         * };*/
        var config = GetPlacementConfigData(placementType);

        if (config != null)
        {
            return(!config.show);
        }
        return(false);
    }
Esempio n. 15
0
    /// <summary>
    /// Get ads network priority order. If there is remote config, get from config, otherwise use default
    /// </summary>
    List <CustomMediation.AD_NETWORK> GetAdsNetworkPriority(AdPlacementType placementType)
    {
        List <CustomMediation.AD_NETWORK> adPriority;

        if (configPlacementAdsNetworkPriority != null)
        {
            adPriority = configPlacementAdsNetworkPriority(placementType);
        }
        else
        {
            adPriority = defaultAdsNetworkPriority;
        }
        return(adPriority);
    }
Esempio n. 16
0
        public void RegisterAdWatch(AdPlacementType type, MetaDataStateBase playerState, Action getAdRewardForTypeMethod)
        {
            AdData      adData      = AdData.GetAdDataForPlacementType(type);
            AdStateItem adStateItem = GetStateItem(adData.PlacementType);

            if (adData != null && (adStateItem.UseCount < adData.DailyMaxUse || adData.DailyMaxUse == 0))
            {
                adStateItem.UseCount++;

                if (getAdRewardForTypeMethod != null)
                {
                    getAdRewardForTypeMethod.Invoke();
                }

                playerState.TotalAdWatchedCount++;
            }
        }
Esempio n. 17
0
        public bool IsVideoAvailable(AdPlacementType type)
        {
            bool avail;
            var  placement = GetPlacementByType(type);

            switch (type)
            {
            default:
                avail = CommonConditions(placement.PlacementName);
                break;

            case AdPlacementType.MysteryItem:
                avail = CommonConditions(placement.PlacementName) && _timersController.IsTimerRunning(AdPlacementType.MysteryItem);
                break;
            }
            return(avail);
        }
Esempio n. 18
0
    /// <param name="onAdClosed">Warning: not completely functional yet, only Admob will call onAdClosed when the interstitial is closed</param>
    public void ShowInterstitial(AdPlacementType placeType, InterstitialDelegate onAdClosed = null)
    {
        if (currentAdsHelper == null)
        {
            Debug.LogError("currentAdsHelper is null due to all ads failed to load");
            return;
        }
        currentAdsHelper.ShowInterstitial(placeType, onAdClosed);

        /*switch (CurrentAdNetwork)
         * {
         *  case CustomMediation.AD_NETWORK.Unity:
         *      UnityAdsManager.ShowInterstitial(CustomMediation.GetUnityPlacementId(placeType));
         *      break;
         *  case CustomMediation.AD_NETWORK.FAN:
         *      _FANHelper.ShowInterstitial(CustomMediation.GetFANPlacementId(placeType));
         *      break;
         * }*/
    }
Esempio n. 19
0
        public float GetRemainingTime(AdPlacementType placementType)
        {
            var adPlacementData = _adPlacements[placementType];

            foreach (var kvp in _timers)
            {
                if (kvp.Key == placementType)
                {
                    var remaining = kvp.Value.Length - kvp.Value.Elapsed;

                    if (remaining <= 0f)
                    {
                        remaining = 0f;
                        RaiseTimerComplete(adPlacementData.PlacementType);
                    }
                    return(remaining);
                }
            }
            return(-1f);
        }
Esempio n. 20
0
        public override async Task <CloudScriptResponse> ExecuteAsync(CloudScriptRequest request, string[] urlArguments)
        {
            DateTime benginRequest = DateTime.UtcNow;

            string playFabId   = urlArguments[0];
            string placementId = urlArguments[1];
            string eventId     = urlArguments[2];

            var cloudData = new PlayFabFileDetails(MetaSettings.MetaDataStateFileName);

            if (await PlayFabApiHandler.GetPlayerTitleData(playFabId, new List <PlayFabFileDetails>()
            {
                cloudData
            }))
            {
                MetaDataState state = MetaDataStateBase.FromJson <MetaDataState>(cloudData.DataAsString);

                AdPlacementType adPlacementType = (AdPlacementType)(Enum.Parse(typeof(AdPlacementType), placementId));
                //state.AdState.RegisterAdWatch(adPlacementType, state, () => AdData.GetAdRewardForTypeMethod(adPlacementType, state));

                cloudData.DataAsString = state.ToJson();

                if (await PlayFabApiHandler.UploadPlayerTitleData(playFabId, new List <PlayFabFileDetails>()
                {
                    cloudData
                }))
                {
                    CloudScriptResponse cloudScriptResponse = new CloudScriptResponse()
                    {
                        ResponseCode = ResponseCode.Success, Method = this.GetType().Name
                    };
                    cloudScriptResponse.Params.Add("status", eventId + ":OK");
                    return(cloudScriptResponse);
                }
            }

            return(new CloudScriptResponse()
            {
                ResponseCode = ResponseCode.Error
            });
        }
Esempio n. 21
0
        private void HandleAccept(AdPlacementType type)
        {
            _timeDispatcher.OnGameplayPause.Invoke(true);
            _timersController.StopTimer(type);
            var placement = GetPlacementByType(type);

            _audioManager.Mute(true);
#if UNITY_EDITOR
            StartCoroutine(WaitBeforeEditorCallback(placement.PlacementName));
#else
            if (placement != null && CommonConditions(placement.PlacementName))
            {
                IronSource.Agent.showRewardedVideo(placement.PlacementName);
            }
            else
            {
                var error = new IronSourceError(-1, "Internal error");
                HandleRewardedVideoAdShowFailed(error);
            }
#endif
        }
Esempio n. 22
0
    IEnumerator CoRequestInterstitialNoShow(AdPlacementType placementType, InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        isLoadingInterstitial = true;
        bool isSuccess = false;
        WaitForSecondsRealtime checkInterval = new WaitForSecondsRealtime(0.05f);

        var adPriority = GetAdsNetworkPriority(placementType);

        for (int i = 0; i < adPriority.Count; i++)
        {
            bool checkAdNetworkDone     = false;
            IAdsNetworkHelper adsHelper = GetAdsNetworkHelper(adPriority[i]);
            if (adsHelper == null)
            {
                continue;
            }
            adsHelper.RequestInterstitialNoShow(placementType,
                                                (success) => { checkAdNetworkDone = true; isSuccess = success; },
                                                showLoading);
            while (!checkAdNetworkDone)
            {
                yield return(checkInterval);
            }
            if (isSuccess)
            {
                //CurrentAdNetwork = AdNetworkSetting.AdNetworks[i];
                currentAdsHelper = adsHelper;
                break;
            }
        }
        //.Log($"AdsManager: CoRequestInterstitialNoShow done {isSuccess}");
        onAdLoaded?.Invoke(isSuccess);
        isLoadingInterstitial = false;
        if (showLoading)
        {
            Manager.LoadingAnimation(false);
        }
    }
Esempio n. 23
0
    bool DoNotShowAds(AdPlacementType placementType)
    {
        bool isNoAds = false;

        if (noAds != null)
        {
            var noAdsInvokeList = noAds.GetInvocationList();
            for (int i = 0; i < noAdsInvokeList.Length; i++)
            {
                isNoAds = isNoAds || (bool)noAdsInvokeList[i].DynamicInvoke();
            }
        }
        //.Log($"AdsManager: do not show ads {placementType}: {isNoAds}");
        if (isNoAds)
        {
            return(true);
        }
        if (configPlacementHideAds != null && configPlacementHideAds(placementType))
        {
            return(true);
        }
        return(false);
    }
Esempio n. 24
0
 public static void ShowError(string msg, AdPlacementType placementType)
 {
     ShowError(msg, placementType.ToString());
 }
Esempio n. 25
0
 public static void Reward(BoolDelegate onFinish, AdPlacementType placementType)
 {
     instance.StartCoroutine(instance.CoReward(onFinish, placementType));
 }
Esempio n. 26
0
    public void RequestInterstitialNoShow(AdPlacementType placementId, AdsManager.InterstitialDelegate onAdLoaded = null, bool showLoading = true)
    {
        string id = CustomMediation.GetAdmobID(placementId, AdMobConst.INTERSTITIAL);

        RequestAdmobInterstitialNoShow(id, onAdLoaded, showLoading);
    }
Esempio n. 27
0
    public void Reward(AdPlacementType placementId, RewardDelegate onFinish)
    {
        string id = CustomMediation.GetAdmobID(placementId, AdMobConst.REWARD_ID);

        RewardAdmob(onFinish, id);
    }
Esempio n. 28
0
 public static AdData GetAdDataForPlacementType(AdPlacementType type)
 {
     return(DataLayer.Instance.GetTable(MetaStateSettings.PolymorhTypes[typeof(AdData)]).Cast <AdData>().Where(y => y.PlacementType == type).SingleOrDefault());
 }
Esempio n. 29
0
 public static T GetById <T>(AdPlacementType type) where T : new()
 {
     return((T)DataLayer.Instance.GetTable <T>().Where(y => ((AdData)(object)y).PlacementType == type).SingleOrDefault());
 }
Esempio n. 30
0
 public bool IsTimerRunning(AdPlacementType placementType)
 {
     return(_timers.ContainsKey(placementType) &&
            !_timers[placementType].IsDone);
 }