Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using AppodealAds.Unity.Api;
  5. using AppodealAds.Unity.Common;
  6. public class AdsManager : MonoBehaviour, IRewardedVideoAdListener {
  7.  
  8. #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IPHONE
  9. string appKey = "";
  10. #elif UNITY_ANDROID
  11. string appKey = "e2ff0545c9c89e3984e2f5fb3c198e4e37ab57a8ba8e0d20";
  12. #elif UNITY_IPHONE
  13. string appKey = "e551d441f7e89390c77abe0b07fb298de2f59955ec08f955";
  14. #else
  15. string appKey = "";
  16. #endif
  17.  
  18. public static float timeOfLastAd = 0f;
  19.  
  20. public static float timeSinceLastAd{
  21. get{
  22. return Time.time - timeOfLastAd;
  23. }
  24. }
  25.  
  26. public static bool BannerIsVisible{
  27. get{
  28. return _bannerIsVisible;
  29. }
  30. }
  31. private static bool _bannerIsVisible;
  32.  
  33. void Start(){
  34. Appodeal.setTesting (false);
  35. Appodeal.setRewardedVideoCallbacks (this);
  36. Appodeal.initialize (appKey, Appodeal.INTERSTITIAL | Appodeal.BANNER | Appodeal.REWARDED_VIDEO);
  37. }
  38.  
  39. public static bool ShowBanner(){
  40. if (Database.userGameCount > 5 && !Database.purchasedNoAds) {
  41. Appodeal.show (Appodeal.BANNER_TOP);
  42. _bannerIsVisible = true;
  43. return true;
  44. }
  45. _bannerIsVisible = false;
  46. return false;
  47. }
  48.  
  49. public static void HideBanner(){
  50. _bannerIsVisible = false;
  51. Appodeal.hide (Appodeal.BANNER);
  52. }
  53.  
  54. public static void ShowInterstitial(){
  55. if(Database.userGameCount>2 && timeSinceLastAd> 2 * 60 && !Database.purchasedNoAds){
  56. if(Appodeal.isLoaded(Appodeal.INTERSTITIAL)){
  57. timeOfLastAd = Time.time;
  58. Appodeal.show (Appodeal.INTERSTITIAL);
  59. }
  60. }
  61. }
  62. public static bool CanShowRewardedVideo(){
  63. return Appodeal.isLoaded (Appodeal.REWARDED_VIDEO);
  64. }
  65. public static void ShowRewardedVideo(){
  66. if(Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)){
  67. Appodeal.show(Appodeal.REWARDED_VIDEO);
  68. timeOfLastAd = Time.time;
  69. }
  70. }
  71.  
  72.  
  73. #region IRewardedVideoAdListener implementation
  74. public void onRewardedVideoLoaded ()
  75. {
  76.  
  77. }
  78. public void onRewardedVideoFailedToLoad ()
  79. {
  80.  
  81. }
  82. public void onRewardedVideoShown ()
  83. {
  84.  
  85. }
  86. public void onRewardedVideoFinished (int amount, string name)
  87. {
  88. GameSparksWrapper.WatchAd ();
  89. }
  90. public void onRewardedVideoClosed ()
  91. {
  92.  
  93. }
  94. #endregion
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement