|
- using System;
- using System.Collections.Generic;
- using SUISS.Core;
- using UnityEngine;
-
- namespace CIG
- {
- public class AdWaterfall
- {
- public AdWaterfall(params AdProviderType[] adProviderSequence)
- {
- this._adProviderSequence = new List<AdProviderType>(adProviderSequence);
- List<AdProviderType> list = new List<AdProviderType>();
- int count = this._adProviderSequence.Count;
- for (int i = 0; i < count; i++)
- {
- AdProviderType item = this._adProviderSequence[i];
- if (!list.Contains(item))
- {
- list.Add(item);
- }
- }
- count = list.Count;
- for (int j = 0; j < count; j++)
- {
- AdProviderType providerType = list[j];
- if (!SingletonMonobehaviour<AdProviderPool>.Instance.AdProviderExists(providerType))
- {
- this._adProviderSequence.RemoveAll((AdProviderType x) => x == providerType);
- UnityEngine.Debug.LogWarningFormat("[AdWaterfall] AdProvider '{0}' doesn't exist. -> Removing all occurances from the provider sequence list.", new object[]
- {
- providerType
- });
- }
- }
- }
-
- public bool ContainsAdProvider(AdProviderType providerType)
- {
- return this._adProviderSequence.Contains(providerType);
- }
-
- public bool ShowAd(Action<bool, bool> callback)
- {
- //TODODO չʾ¼¤ÀøÊÓÆµ
- callback(true, true);
- return true;
-
- if (!this.IsReady)
- {
- return false;
- }
- int count = this._adProviderSequence.Count;
- int i = 0;
- while (i < count)
- {
- AdProviderType adProviderType = this._adProviderSequence[i];
- if (SingletonMonobehaviour<AdProviderPool>.Instance.IsReady(adProviderType))
- {
- if (SingletonMonobehaviour<AdProviderPool>.Instance.ShowAd(adProviderType, callback))
- {
- this._adProviderSequence.RemoveAt(i);
- this._adProviderSequence.Add(adProviderType);
- return true;
- }
- UnityEngine.Debug.LogErrorFormat("[AdWaterfall] Failed to ShowAd for '{0}'", new object[]
- {
- adProviderType
- });
- return false;
- }
- else
- {
- i++;
- }
- }
- return false;
- }
-
- public virtual bool IsReady
- {
- get
- {
- int count = this._adProviderSequence.Count;
- if (count == 0)
- {
- return false;
- }
- for (int i = 0; i < count; i++)
- {
- if (SingletonMonobehaviour<AdProviderPool>.Instance.IsReady(this._adProviderSequence[i]))
- {
- return true;
- }
- }
- return false;
- }
- }
-
- private List<AdProviderType> _adProviderSequence;
- }
- }
|