Advertisement
Guest User

Untitled

a guest
Apr 29th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using Kiloo.Common.Ads;
  2. using Kiloo.Common.Utility;
  3. using Kiloo.Monetization.AdColonyPlugin;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using Object = UnityEngine.Object;
  9.  
  10. namespace Kiloo.Monetization
  11. {
  12. public class AdColonyAdProvider : AbstractAdProvider
  13. {
  14. public const string ID = "adcolony";
  15.  
  16. private string _showLocation;
  17. private bool _addedListeners;
  18. private MonoBehaviour _coroutineRunner;
  19. List<string> _cachedLocationIds = new List<string>();
  20. bool _receivedReward;
  21.  
  22. public override string id
  23. {
  24. get { return ID; }
  25. }
  26.  
  27. public override bool supportsMulticaching
  28. {
  29. get { return false; }
  30. }
  31.  
  32. protected override bool HasCachedVideo(string cacheID)
  33. {
  34. return _cachedLocationIds.Contains(cacheID);
  35. }
  36.  
  37. protected override void OnInitialize(AdProviderConfiguration configuration)
  38. {
  39. if (!_addedListeners)
  40. {
  41. // Utku: Do not use the event below as it can be triggered AFTER the video has played on Android.
  42. // AdColony.onAdStarted += AdStarted;
  43. /*
  44. AdColony.onV4VCReward += success =>
  45. {
  46. // Log.Info("V4VC reward: " + success);
  47. _receivedReward = success;
  48. };
  49.  
  50. AdColony.onAdAttemptFinished += shown =>
  51. {
  52. if (_receivedReward)
  53. {
  54. // Log.Info("Finished watching video");
  55. _receivedReward = false;
  56. eventInvoker.FinishedWatchingVideo(id, _showLocation);
  57. }
  58.  
  59. // Log.Info("Ad dismissed");
  60. eventInvoker.DismissedAd(AdType.Video, id, _showLocation);
  61. };*/
  62.  
  63. _coroutineRunner = new GameObject("AdColonyCoroutineRunner").AddComponent<MonoBehaviour>();
  64. Object.DontDestroyOnLoad(_coroutineRunner.gameObject);
  65.  
  66. _addedListeners = true;
  67. }
  68.  
  69. try
  70. {
  71. AdColony.Configure(configuration.appID, configuration.zoneIDs);
  72. FinishIntialization(true);
  73. }
  74. catch (Exception e)
  75. {
  76. Debug.LogError(e.Message);
  77. FinishIntialization(false);
  78. }
  79. }
  80.  
  81. protected override void CacheVideo(string adLocationID, string cacheID)
  82. {
  83. if (!_cachedLocationIds.Contains(cacheID))
  84. {
  85. _coroutineRunner.StartCoroutine(CheckCacheState(adLocationID, cacheID));
  86. }
  87. else
  88. {
  89. eventInvoker.CachedAd(AdType.Video, id, adLocationID);
  90. }
  91. }
  92.  
  93. protected override void ShowVideo(string adLocationID, string cacheID)
  94. {
  95. if (_cachedLocationIds.Contains(cacheID))
  96. {
  97. _cachedLocationIds.Remove(cacheID);
  98. }
  99. _showLocation = adLocationID;
  100.  
  101. AdStarted();
  102. //AdColony.PlayVideoAdForZoneWithPopups(cacheID, false, false);
  103. }
  104.  
  105. private IEnumerator CheckCacheState(string adLocationID, string cacheID)
  106. {
  107. eventInvoker.StartedCachingAd(AdType.Video, id, adLocationID);
  108. /*
  109. while (!AdColony.IsVirtualCurrencyAwardAvailable(cacheID))
  110. {
  111. yield return Wait.For(1f).UnscaledSeconds().StartCoroutine();
  112. }*/
  113.  
  114. _cachedLocationIds.Add(cacheID);
  115. eventInvoker.CachedAd(AdType.Video, id, adLocationID);
  116. yield return null;
  117. }
  118.  
  119. void AdStarted()
  120. {
  121. // Log.Info ("Ad started");
  122. _receivedReward = false;
  123. eventInvoker.ShowedAd (AdType.Video, id, _showLocation);
  124. }
  125.  
  126. protected override void OnCacheTimeout(AdType adType, string adLocationID)
  127. {
  128. // Log.Warn("Cache timeout");
  129. _coroutineRunner.StopAllCoroutines();
  130. }
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement