|
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using CIG.Extensions;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
-
- namespace CIG
- {
- public sealed class AdColonyVideoAdsProvider : Singleton<AdColonyVideoAdsProvider>, IAdProvider
- {
- public AdColonyVideoAdsProvider()
- {
- GameObject gameObject = new GameObject("AdColonyVideoAdsProvider");
- UnityEngine.Object.DontDestroyOnLoad(gameObject);
- gameObject.hideFlags = HideFlags.HideAndDontSave;
- this._providerMonoBehaviour = gameObject.AddComponent<AdProviderMonoBehaviour>();
- }
-
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event AdAvailabilityChangedEventHandler AvailabilityChangedEvent;
-
- private void FireAvailabilityChangedEvent()
- {
- if (this.AvailabilityChangedEvent != null)
- {
- this.AvailabilityChangedEvent(this);
- }
- }
-
- public void StartCaching()
- {
- AdProviderState providerState = this._providerState;
- if (providerState != AdProviderState.None)
- {
- if (providerState == AdProviderState.Initialized)
- {
- AdState adState = this._adState;
- if (adState == AdState.None)
- {
- if (SingletonMonobehaviour<CIGWebService>.IsAvailable)
- {
- this.RequestAd();
- }
- else
- {
- this.TrySchedulingDelayedCachingRoutine(false);
- }
- }
- }
- }
- else
- {
- this._providerState = AdProviderState.Initializing;
- }
- }
-
- public bool ShowAd(Action<bool, bool> callback)
- {
- if (this.IsReady)
- {
- this._callback = callback;
- this._adState = AdState.Showing;
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("video_adcolony");
- this.FireAvailabilityChangedEvent();
- return true;
- }
- return false;
- }
-
- public bool IsReady
- {
- get
- {
- return true;
- }
- }
-
- public AdType AdType
- {
- get
- {
- return AdType.Video;
- }
- }
-
- public AdProviderType AdProviderType
- {
- get
- {
- return AdProviderType.AdColony;
- }
- }
-
- private void RequestAd()
- {
- if (this._adState == AdState.None)
- {
- this._adState = AdState.Requesting;
- }
- }
-
- private void TrySchedulingDelayedCachingRoutine(bool applyBackOff)
- {
- if (this._providerMonoBehaviour.IsInvoking(new Action(this.StartCaching)))
- {
- return;
- }
- float num = 5f;
- if (applyBackOff)
- {
- this._backOffSeconds = Mathf.Min(this._backOffSeconds + 5f, 120f);
- num += this._backOffSeconds;
- }
- this._providerMonoBehaviour.InvokeOnMainThread(new Action(this.StartCaching), num);
- UnityEngine.Debug.LogWarningFormat("[AdColonyVideoAdsProvider] Ad Failed To Load. Retrying in {0} seconds", new object[]
- {
- num
- });
- }
-
- private void OnInterstitialRequestFailed(string zoneId)
- {
- this._adState = AdState.None;
- this.FireAvailabilityChangedEvent();
- this.TrySchedulingDelayedCachingRoutine(true);
- }
-
- private string AppId
- {
- get
- {
- return "appd8e9f08158fe4a8699";
- }
- }
-
- private string ZoneId
- {
- get
- {
- return "vz029f1a6cf9c6441da3";
- }
- }
-
- private const string PlaystoreAppId = "appd8e9f08158fe4a8699";
-
- private const string PlaystoreZoneId = "vz029f1a6cf9c6441da3";
-
- private const string iOSAppId = "app59433fd945004fe589";
-
- private const string iOSZoneId = "vz47742197eb404046af";
-
- private const string AmazonAppId = "app8bd11f9f7d3b4770ba";
-
- private const string AmazonZoneId = "vzf1bbc5c82e50491b89";
-
- private const float MaxBackOffSeconds = 120f;
-
- private AdProviderState _providerState;
-
- private AdState _adState;
-
- private Action<bool, bool> _callback;
-
- private float _backOffSeconds;
-
- private AdProviderMonoBehaviour _providerMonoBehaviour;
- }
- }
|