Exemple #1
0
        public static void RequestAd(
            string zoneId,
            Boolean isCached,
            Action <TapsellAd> onAdAvailableAction,
            Action <string> onNoAdAvailableAction,
            Action <TapsellError> onErrorAction,
            Action <string> onNoNetworkAction,
            Action <TapsellAd> onExpiringAction,
            Action <TapsellAd> onOpenedAction,
            Action <TapsellAd> onClosedAction)
        {
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            if (adFilledPool.ContainsKey(zoneId))
            {
                adFilledPool.Remove(zoneId);
            }

            if (errorPool.ContainsKey(zoneId))
            {
                errorPool.Remove(zoneId);
            }

            if (noAdAvailablePool.ContainsKey(zoneId))
            {
                noAdAvailablePool.Remove(zoneId);
            }

            if (noNetworkPool.ContainsKey(zoneId))
            {
                noNetworkPool.Remove(zoneId);
            }

            if (expiringPool.ContainsKey(zoneId))
            {
                expiringPool.Remove(zoneId);
            }

            if (adOpenedPool.ContainsKey(zoneId))
            {
                adOpenedPool.Remove(zoneId);
            }

            if (adClosedPool.ContainsKey(zoneId))
            {
                adClosedPool.Remove(zoneId);
            }

            adFilledPool.Add(zoneId, onAdAvailableAction);
            errorPool.Add(zoneId, onErrorAction);
            noAdAvailablePool.Add(zoneId, onNoAdAvailableAction);
            noNetworkPool.Add(zoneId, onNoNetworkAction);
            expiringPool.Add(zoneId, onExpiringAction);

            if (onOpenedAction != null)
            {
                adOpenedPool.Add(zoneId, onOpenedAction);
            }

            if (onClosedAction != null)
            {
                adClosedPool.Add(zoneId, onClosedAction);
            }
#endif

#if UNITY_ANDROID && !UNITY_EDITOR
            tapsell.CallStatic("requestAd", zoneId, isCached);
#elif UNITY_IOS && !UNITY_EDITOR
            string cached = "false";
            if (isCached)
            {
                cached = "true";
            }
            _TSRequestAdForZone(zone, cached);
#else
            TapsellError error = new TapsellError();
            error.zoneId  = zoneId;
            error.message = "Tapsell ads are only available on Android and iOS platforms.";
            onErrorAction(error);
#endif
        }
Exemple #2
0
        /// <summary>
        /// Requests an ad from Tapsell SDK.
        /// </summary>
        /// <returns><c>true</c>, if ad was requested, <c>false</c> otherwise.</returns>
        /// <param name="zoneId">Zone identifier.</param>
        /// <param name="isCached">If set to <c>true</c> is cached, else streamed.</param>
        /// <param name="onAdAvailableAction">On ad available action.</param>
        /// <param name="onNoAdAvailableAction">On no ad available action.</param>
        /// <param name="onErrorAction">On error action.</param>
        /// <param name="onNoNetworkAction">On no network action.</param>
        /// <param name="onExpiringAction">On expiring action.</param>
        public static bool requestAd(string zoneId, Boolean isCached, Action <TapsellAd> onAdAvailableAction, Action <string> onNoAdAvailableAction,
                                     Action <TapsellError> onErrorAction, Action <string> onNoNetworkAction, Action <TapsellAd> onExpiringAction, Action <TapsellAd> onOpenedAction,
                                     Action <TapsellAd> onClosedAction)
        {
                        #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
            string zone = zoneId;
            if (String.IsNullOrEmpty(zoneId))
            {
                zoneId = "defaultTapsellZone";
            }
            if (requestAdAvailablePool.ContainsKey(zoneId))
            {
                requestAdAvailablePool.Remove(zoneId);
            }
            requestAdAvailablePool.Add(zoneId, onAdAvailableAction);

            if (requestErrorPool.ContainsKey(zoneId))
            {
                requestErrorPool.Remove(zoneId);
            }
            requestErrorPool.Add(zoneId, onErrorAction);

            if (requestNoAdAvailablePool.ContainsKey(zoneId))
            {
                requestNoAdAvailablePool.Remove(zoneId);
            }
            requestNoAdAvailablePool.Add(zoneId, onNoAdAvailableAction);

            if (requestNoNetworkPool.ContainsKey(zoneId))
            {
                requestNoNetworkPool.Remove(zoneId);
            }
            requestNoNetworkPool.Add(zoneId, onNoNetworkAction);

            if (requestExpiringPool.ContainsKey(zoneId))
            {
                requestExpiringPool.Remove(zoneId);
            }
            requestExpiringPool.Add(zoneId, onExpiringAction);

            if (requestAdOpenedPool.ContainsKey(zoneId))
            {
                requestAdOpenedPool.Remove(zoneId);
            }
            if (onOpenedAction != null)
            {
                requestAdOpenedPool.Add(zoneId, onOpenedAction);
            }

            if (requestAdClosedPool.ContainsKey(zoneId))
            {
                requestAdClosedPool.Remove(zoneId);
            }
            if (onClosedAction != null)
            {
                requestAdClosedPool.Add(zoneId, onClosedAction);
            }
                        #endif
                        #if UNITY_ANDROID && !UNITY_EDITOR
            return(tapsell.CallStatic <Boolean>("requestAd", zone, isCached));
                        #elif UNITY_IOS && !UNITY_EDITOR
            string cached = "false";
            if (isCached)
            {
                cached = "true";
            }
            _TSRequestAdForZone(zone, cached);
            return(true);
                        #else
            TapsellError error = new TapsellError();
            error.zoneId = zoneId;
            error.error  = "Tapsell ads are only available on Android and iOS platforms.";
            return(false);
                        #endif
        }