You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
3.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using SUISS.Core;
  4. using UnityEngine;
  5. namespace CIG
  6. {
  7. public class AdWaterfall
  8. {
  9. public AdWaterfall(params AdProviderType[] adProviderSequence)
  10. {
  11. this._adProviderSequence = new List<AdProviderType>(adProviderSequence);
  12. List<AdProviderType> list = new List<AdProviderType>();
  13. int count = this._adProviderSequence.Count;
  14. for (int i = 0; i < count; i++)
  15. {
  16. AdProviderType item = this._adProviderSequence[i];
  17. if (!list.Contains(item))
  18. {
  19. list.Add(item);
  20. }
  21. }
  22. count = list.Count;
  23. for (int j = 0; j < count; j++)
  24. {
  25. AdProviderType providerType = list[j];
  26. if (!SingletonMonobehaviour<AdProviderPool>.Instance.AdProviderExists(providerType))
  27. {
  28. this._adProviderSequence.RemoveAll((AdProviderType x) => x == providerType);
  29. UnityEngine.Debug.LogWarningFormat("[AdWaterfall] AdProvider '{0}' doesn't exist. -> Removing all occurances from the provider sequence list.", new object[]
  30. {
  31. providerType
  32. });
  33. }
  34. }
  35. }
  36. public bool ContainsAdProvider(AdProviderType providerType)
  37. {
  38. return this._adProviderSequence.Contains(providerType);
  39. }
  40. public bool ShowAd(Action<bool, bool> callback)
  41. {
  42. //TODODO չʾ¼¤ÀøÊÓÆµ
  43. callback(true, true);
  44. return true;
  45. if (!this.IsReady)
  46. {
  47. return false;
  48. }
  49. int count = this._adProviderSequence.Count;
  50. int i = 0;
  51. while (i < count)
  52. {
  53. AdProviderType adProviderType = this._adProviderSequence[i];
  54. if (SingletonMonobehaviour<AdProviderPool>.Instance.IsReady(adProviderType))
  55. {
  56. if (SingletonMonobehaviour<AdProviderPool>.Instance.ShowAd(adProviderType, callback))
  57. {
  58. this._adProviderSequence.RemoveAt(i);
  59. this._adProviderSequence.Add(adProviderType);
  60. return true;
  61. }
  62. UnityEngine.Debug.LogErrorFormat("[AdWaterfall] Failed to ShowAd for '{0}'", new object[]
  63. {
  64. adProviderType
  65. });
  66. return false;
  67. }
  68. else
  69. {
  70. i++;
  71. }
  72. }
  73. return false;
  74. }
  75. public virtual bool IsReady
  76. {
  77. get
  78. {
  79. int count = this._adProviderSequence.Count;
  80. if (count == 0)
  81. {
  82. return false;
  83. }
  84. for (int i = 0; i < count; i++)
  85. {
  86. if (SingletonMonobehaviour<AdProviderPool>.Instance.IsReady(this._adProviderSequence[i]))
  87. {
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. }
  94. private List<AdProviderType> _adProviderSequence;
  95. }
  96. }