예제 #1
0
        public virtual void HideAdvertisement(AdsTypes type, Action onAdHidden = null,
                                              bool shouldReleaseFromCache      = false)
        {
            if (_engagedAdvertisers == null || !_engagedAdvertisers.Any())
            {
                return;
            }

            Debug.Log("Hiding Ad: Type- " + type);

            //early exit when there is init error
            if (_errorInInitialization)
            {
                return;
            }

            _engagedAdvertisers.ForEach(service =>
            {
                var adsInterface = service as IAdsInterface;
                if (adsInterface != null)
                {
                    //adding the set status method to the on ad shown action
                    onAdHidden += () =>
                    {
                        service.SetAdServedStatus(type, false);
                        OnAdsHidden.SafeInvoke(type);
                    };

                    adsInterface.HideAd(type, onAdHidden, shouldReleaseFromCache);
                }
            });
        }
예제 #2
0
        //------------------------------------------------------------------------
        public static string GetAdvertiseFile(AdsTypes adtype, string fileVirtualPath, int adID, int width, int height, string title, bool hasLink)
        {
            string target   = "/Website/Advs/ViewAd.aspx?id=" + adID.ToString();
            string adObject = "";

            switch (adtype)
            {
            case AdsTypes.Photo:
                if (adID > 0 && hasLink)
                {
                    adObject += "<a href='" + target + "' target='_blank' >";
                }

                adObject += "<img title='" + title + "' src='" + fileVirtualPath + "' width='" + width.ToString() + "' alt='" + title + "' height='" + height.ToString() + "' border=0>";

                if (adID > 0 && hasLink)
                {
                    adObject += "</a>";
                }

                break;

            case AdsTypes.Flash:
                adObject = PlayersBuilder.BuildFlashPlayer(fileVirtualPath, width, height, "ffffff");
                break;
            }

            return(adObject);
        }
예제 #3
0
        public void HideAd(AdsTypes type, Action onAdHidden, bool shouldReleaseFromCache)
        {
            switch (type)
            {
            case AdsTypes.Banner:
            {
                _demoAdsUi.BannerAd.CloseAd(onAdHidden);
            }
            break;

            case AdsTypes.Interstitial:
            {
                _demoAdsUi.InterstitialAd.CloseAd(onAdHidden);
            }
            break;

            case AdsTypes.RewardedVideo:
            {
                _demoAdsUi.RewardingVideoAd.CloseAd(onAdHidden);
            }
            break;

            default:
            {
                Debug.Log("Invalid ad type!!!");
            }
                return;
            }
        }
예제 #4
0
        public void ShowAdvertisement(AdsTypes type, AdsPositions position = AdsPositions.Top, Action onAdShown = null,
                                      Action onAdClicked = null, Action <object> onRewarded                = null, Action <string> onFail = null,
                                      bool forceAds      = false, Dictionary <string, object> extraOptions = null, float invokeDelay      = 0,
                                      Action onSkipped   = null)
        {
            if (!LocalDataManager.Instance.IsConnectedToInternet)
            {
                Debug.Log("Show ads ignored, as there is not internet connectivity.");
                return;
            }

            Debug.LogFormat("Ads Manager::: -> Premium User: {0} \n-> Force Ads: {1}", _isPremiumUser, forceAds);

            //debug
            if (BaseSettings.Instance.ForceAds)
            {
                Debug.Log("Debug force Ads is true, ignoring premium status.");
            }

            if (!BaseSettings.Instance.ForceAds && !forceAds) //game setting->forceAds is use for debug
            {
                if (_isPremiumUser)
                {
                    return;
                }
            }

            Debug.Log("Showing Ad: Type- " + type + " Extra options: " + JsonConvert.SerializeObject(extraOptions) +
                      " with delay: " + invokeDelay);
            StartCoroutine(ShowAds(type, position, onAdShown, onAdClicked, onRewarded, onFail, extraOptions,
                                   invokeDelay, onSkipped));
        }
예제 #5
0
        public static string ConvertAdName(string objectName, AdsTypes inputType, AdsTypes outputType)
        {
            string domain;

            if (inputType.Equals(AdsTypes.AdsNameTypeNt4))
            {
                objectName = objectName.Replace("/", "\\");
            }

            switch (inputType)
            {
            case AdsTypes.AdsNameTypeNt4:
                domain = objectName.Split('\\')[0];
                break;

            case AdsTypes.AdsNameTypeDomainSimple:
                domain = objectName.Split('@')[1];
                break;

            case AdsTypes.AdsNameTypeCanonical:
                domain = objectName.Split('/')[0];
                break;

            case AdsTypes.AdsNameTypeDn:
                domain = objectName.Substring(objectName.IndexOf("DC=", StringComparison.Ordinal)).Replace("DC=", "").Replace(",", ".");
                break;

            default:
                domain = "";
                break;
            }

            try
            {
                var translateName     = Type.GetTypeFromProgID("NameTranslate");
                var translateInstance = Activator.CreateInstance(translateName);

                var args = new object[2];
                args[0] = 1;
                args[1] = domain;
                translateName.InvokeMember("Init", BindingFlags.InvokeMethod, null, translateInstance, args);

                args    = new object[2];
                args[0] = (int)inputType;
                args[1] = objectName;
                translateName.InvokeMember("Set", BindingFlags.InvokeMethod, null, translateInstance, args);

                args    = new object[1];
                args[0] = (int)outputType;

                var result = (string)translateName.InvokeMember("Get", BindingFlags.InvokeMethod, null, translateInstance, args);

                return(result);
            }
            catch
            {
                return(null);
            }
        }
예제 #6
0
 public ActionCategory(EventType eventType, AdsTypes type, Action <object> inAction)
 {
     EventType = eventType;
     if (inAction != null)
     {
         ActionDataList.SafeAdd(type, inAction);
     }
 }
예제 #7
0
        protected virtual IEnumerator ShowAds(AdsTypes type, AdsPositions position = AdsPositions.Top,
                                              Action onAdShown       = null, Action onAdClicked = null, Action <object> onRewarded = null,
                                              Action <string> onFail = null, Dictionary <string, object> extraOptions = null, float invokeDelay = 0,
                                              Action onSkipped       = null)
        {
            yield return(new WaitForSeconds(invokeDelay));

            //early exit when there is init error or if the user is a premium user
            if (_errorInInitialization)
            {
                yield break;
            }

            if (_systemsWithAdsAvailable.Count < 1)
            {
                Debug.LogWarning("Error: No Ads Available");
                onFail.SafeInvoke("No Ads Available");
                yield break;
            }

            //sort the system that has ads based on priority
            _systemsWithAdsAvailable.Sort((x, y) => x.Priority.CompareTo(y.Priority));

            var firstPriority = _systemsWithAdsAvailable.Find(x => x.IsAdsAvailable(type, extraOptions));

            if (firstPriority == null)
            {
                Debug.LogWarning("Ad type of : " + type + " is not available in all systems.");
                yield break;
            }

            if (!firstPriority.IsApiInitialized() || !firstPriority.IsAdsAvailable(type, extraOptions))
            {
                Debug.LogWarningFormat("System Initialized: {0}.\nAds available in the system: {1}",
                                       firstPriority.IsApiInitialized(), firstPriority.IsAdsAvailable(type, extraOptions));
                yield break;
            }

            var adsInterface = firstPriority as IAdsInterface;

            if (adsInterface != null)
            {
                //adding the set status method to the on ad shown action
                onAdShown += () =>
                {
                    firstPriority.SetAdServedStatus(type, true);
                    OnAdsShown.SafeInvoke(type, position);
                };

                onRewarded += obj => { OnRewardVideoCompleted.SafeInvoke(); };

                adsInterface.ShowAd(type, position, onAdShown, onAdClicked, onRewarded, extraOptions, onSkipped);
                _engagedAdvertisers.AddUnique(firstPriority);
            }
        }
예제 #8
0
        public void ShowAd(AdsTypes type, float duration = -1, AdsPositions position = AdsPositions.Bottom, Action <object> onRewarded = null, bool skippable = false, Action onSkipped = null)
        {
            this.Activate();

            switch (type)
            {
            case AdsTypes.Banner:
            {
                this.InvokeAfter(() => CloseButton.interactable = true, 0.1f, ignoreUnityTimeScale: true);

                switch (position)
                {
                case AdsPositions.Top:
                {
                    ParentLayout.childAlignment = TextAnchor.UpperCenter;
                }
                break;

                case AdsPositions.Bottom:
                {
                    ParentLayout.childAlignment = TextAnchor.LowerCenter;
                }
                break;
                }
            }
            break;

            case AdsTypes.Interstitial:
            case AdsTypes.RewardedVideo:
            {
                _remainingTimer = duration;
                _onRewarded     = onRewarded;
                _onSkipped      = onSkipped;

                if (skippable)
                {
                    this.InvokeAfter(() => CloseButton.interactable = true, 0.1f, ignoreUnityTimeScale: true);
                }

                this.InvokeAfter(() => CloseButton.interactable = true, duration, (elapsedTime) =>
                    {
                        _remainingTimer       = duration - elapsedTime;
                        TimerImage.fillAmount = elapsedTime / duration;
                    }, 0.1f, ignoreUnityTimeScale: true);

                Time.timeScale = 0;
            }
            break;
            }

            _tween = DemoText.DOPunchRotation(Vector3.one, 0.3f).SetEase(Ease.InOutElastic).SetLoops(-1, LoopType.Incremental).SetUpdate(true);


            OnAdShown.SafeInvoke();
        }
예제 #9
0
        //todo: ad Click events

        #endregion

        #region Actions

        public void SetAdServedStatus(AdsTypes type, bool isActive)
        {
            var entry = new AdStatus(type, isActive);

            if (isActive)
            {
                AdsServedStatus.AddUnique(entry, item => !item.Type.Equals(entry.Type));
            }
            else
            {
                AdsServedStatus.FindAndRemove(x => x.Type.Equals(entry.Type));
            }
        }
예제 #10
0
        public void RequestAdvertisement(AdsTypes type, Action <int> onSuccess = null, Action onFail     = null,
                                         AdsPositions position = AdsPositions.Top, float timeOutDuration = 5,
                                         Dictionary <string, object> extraOptions = null)
        {
            if (!LocalDataManager.Instance.IsConnectedToInternet)
            {
                Debug.Log("Request ads ignored, as there is not internet connectivity.");
                onFail.SafeInvoke();
                return; //early return if there is not internet connectivity
            }


            Debug.Log("Requesting Ad: Type- " + type + " Extra options: " + JsonConvert.SerializeObject(extraOptions));
            StartCoroutine(RequestAds(type, onSuccess, onFail, position, timeOutDuration, extraOptions));
        }
예제 #11
0
        public void ShowAd(AdsTypes type, AdsPositions position, Action onAdShown, Action onAdClicked, Action <object> onRewarded, Dictionary <string, object> extraOptions = null, Action onSkipped = null)
        {
            if (!IsConsentGiven || !Isinitialized)
            {
                Debug.LogWarning("Consent: " + IsConsentGiven + ", Initialized: " + Isinitialized);
                return;
            }

            switch (type)
            {
            case AdsTypes.Banner:
            {
                if (_isBannerReady)
                {
                    _demoAdsUi.BannerAd.ShowAd(AdsTypes.Banner, position: position);
                }
            }
            break;

            case AdsTypes.Interstitial:
            {
                if (_isInterstitialReady)
                {
                    _demoAdsUi.InterstitialAd.ShowAd(AdsTypes.Interstitial, 5, skippable: extraOptions != null && (bool)extraOptions.SafeRetrieve("skippable"), onSkipped: onSkipped);
                }
            }
            break;

            case AdsTypes.RewardedVideo:
            {
                if (_isRewardVideoReady)
                {
                    _demoAdsUi.RewardingVideoAd.ShowAd(AdsTypes.RewardedVideo, Random.Range(6, 10), onRewarded: onRewarded, skippable: extraOptions != null && (bool)extraOptions.SafeRetrieve("skippable"), onSkipped: onSkipped);
                }
            }
            break;

            default:
            {
                Debug.Log("Invalid ad type!!!");
            }
                return;
            }

            onAdShown.SafeInvoke();
        }
예제 #12
0
        public void CreateActions(AdsTypes type, Action inAction, ActionType actionType, EventType eventType)
        {
            if (actionType == ActionType.Success)
            {
                var addedElement = _successActions.Find(x => x.EventType.Equals(eventType));

                if (inAction == null) //early exit if inAction is null
                {
                    return;
                }

                //if already present
                if (addedElement != null)
                {
                    addedElement.ActionList.SafeAdd(type, inAction);
                }
                else
                {
                    var elementToAdd = new ActionCategory(eventType, type, inAction);

                    _successActions.Add(elementToAdd);
                }
            }
            else
            {
                var addedElement = _failActions.Find(x => x.EventType.Equals(eventType));

                if (inAction == null) //early exit if inAction is null
                {
                    return;
                }

                //if already present
                if (addedElement != null)
                {
                    addedElement.ActionList.SafeAdd(type, inAction);
                }
                else
                {
                    var elementToAdd = new ActionCategory(eventType, type, inAction);

                    _failActions.Add(elementToAdd);
                }
            }
        }
예제 #13
0
        public void ActionInvoke(AdsTypes type, ActionType actionType, EventType eventType, object data = null)
        {
            if (actionType == ActionType.Success)
            {
                if (_successActions.Count < 1)
                {
                    return;
                }

                var item = _successActions.Find(x => x.EventType.Equals(eventType));
                if (item != null)
                {
                    item.ActionList.SafeRetrieve(type).SafeInvoke();
                    item.ActionList.Remove(type);

                    if (data != null)
                    {
                        item.ActionDataList.SafeRetrieve(type).SafeInvoke(data);
                        item.ActionDataList.Remove(type);
                    }
                }
            }
            else
            {
                if (_failActions.Count < 1)
                {
                    return;
                }

                var item = _failActions.Find(x => x.EventType.Equals(eventType));
                if (item != null)
                {
                    item.ActionList.SafeRetrieve(type).SafeInvoke();
                    item.ActionList.Remove(type);

                    if (data != null)
                    {
                        item.ActionDataList.SafeRetrieve(type).SafeInvoke(data);
                        item.ActionDataList.Remove(type);
                    }
                }
            }
        }
예제 #14
0
        public bool IsAdAvailable(AdsTypes type, Dictionary <string, object> extraOptions = null)
        {
            var isReady = false;

            switch (type)
            {
            case AdsTypes.Banner:
                isReady = _isBannerReady;
                break;

            case AdsTypes.Interstitial:
                isReady = _isInterstitialReady;
                break;

            case AdsTypes.RewardedVideo:
                isReady = _isRewardVideoReady;
                break;
            }
            //for demo ads, ads become available as soon as it is requested

            return(isReady);
        }
예제 #15
0
        public virtual bool IsAdsAvailable(AdsTypes type, Dictionary <string, object> extraOptions = null)
        {
            if (_systemsWithAdsAvailable == null || !_systemsWithAdsAvailable.Any() ||
                !LocalDataManager.Instance.IsConnectedToInternet)
            {
                return(false);
            }

            //sort the system that has ads based on priority
            _systemsWithAdsAvailable.Sort((x, y) => x.Priority.CompareTo(y.Priority));

            var firstPriority = _systemsWithAdsAvailable.Find(x => x.IsAdsAvailable(type, extraOptions));

            if (firstPriority != null)
            {
                Debug.LogFormat($"Ad system type - {type} is available");
                return(true);
            }

            Debug.LogWarningFormat("Ad system type - {0} is not Available", type);
            return(false);
        }
예제 #16
0
        public void RequestAd(AdsTypes type, Action onSuccess, Action onFail, AdsPositions position, Dictionary <string, object> extraOptions = null)
        {
            if (!IsConsentGiven || !Isinitialized)
            {
                Debug.LogWarning("Consent: " + IsConsentGiven + ", Initialized: " + Isinitialized);
                return;
            }

            AssignedActions.CreateActions(type, onSuccess, Actions.ActionType.Success, Actions.EventType.Request);

            switch (type)
            {
            case AdsTypes.Banner:
            {
                OnBannerAdCached();
            }
            break;

            case AdsTypes.Interstitial:
            {
                OnInterstitialAdCached();
            }
            break;

            case AdsTypes.RewardedVideo:
            {
                OnRewardVideoAdCached(true);
            }
            break;

            default:
            {
                Debug.Log("Invalid ad type!!!");
                return;
            }
            }
        }
예제 #17
0
        public bool IsAdsAvailable(AdsTypes type, Dictionary <string, object> extraOptions)
        {
            var adsInterface = this as IAdsInterface;

            return(adsInterface != null && adsInterface.IsAdAvailable(type, extraOptions));
        }
예제 #18
0
 public AdStatus(AdsTypes type, bool isShowing)
 {
     Type      = type;
     IsShowing = isShowing;
 }
예제 #19
0
        protected virtual IEnumerator RequestAds(AdsTypes type, Action <int> onSuccess = null, Action onFail     = null,
                                                 AdsPositions position = AdsPositions.Top, float timeOutDuration = 8,
                                                 Dictionary <string, object> extraOptions = null)
        {
            bool timeOut = false;

            //early exit when there is init error
            if (_errorInInitialization)
            {
                onFail.SafeInvoke();
                yield return(new WaitForEndOfFrame());

                _isRequestingAds = false;
                yield break;
            }

            _isRequestingAds = true;
            var requestCount = 0;

            try
            {
                _availableAdsSystem.ForEach(x =>
                {
                    var adsInterface = x as IAdsInterface;
                    if (adsInterface != null)
                    {
                        adsInterface.RequestAd(type, () =>
                        {
                            _systemsWithAdsAvailable.AddUnique(x);

                            requestCount++;
                        }, () => { requestCount++; }, position, extraOptions);
                    }
                });
            }
            catch (Exception e)
            {
                Debug.Log("Ad Request error: " + e);
                timeOut = true;
            }


            this.InvokeAfter(() => timeOut = true, timeOutDuration);

            //wait till all the request are processed and callbacks received
            yield return(new WaitUntil(() => requestCount.Equals(_availableAdsSystem.Count) || timeOut));

            // _systemsWithAdsAvailable = _systemsWithAdsAvailable.Distinct().ToList();

            var adsFound = _systemsWithAdsAvailable.Count(x => x.IsAdsAvailable(type, extraOptions));

            if (adsFound > 0)
            {
                onSuccess.SafeInvoke(adsFound);
            }
            else
            {
                onFail.SafeInvoke();
            }

            yield return(new WaitForEndOfFrame());

            _isRequestingAds = false;
        }