Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using AppodealAds.Unity.Api;
- using AppodealAds.Unity.Common;
- public class AdsManager : MonoBehaviour, IRewardedVideoAdListener {
- #if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IPHONE
- string appKey = "";
- #elif UNITY_ANDROID
- string appKey = "e2ff0545c9c89e3984e2f5fb3c198e4e37ab57a8ba8e0d20";
- #elif UNITY_IPHONE
- string appKey = "e551d441f7e89390c77abe0b07fb298de2f59955ec08f955";
- #else
- string appKey = "";
- #endif
- public static float timeOfLastAd = 0f;
- public static float timeSinceLastAd{
- get{
- return Time.time - timeOfLastAd;
- }
- }
- public static bool BannerIsVisible{
- get{
- return _bannerIsVisible;
- }
- }
- private static bool _bannerIsVisible;
- void Start(){
- Appodeal.setTesting (false);
- Appodeal.setRewardedVideoCallbacks (this);
- Appodeal.initialize (appKey, Appodeal.INTERSTITIAL | Appodeal.BANNER | Appodeal.REWARDED_VIDEO);
- }
- public static bool ShowBanner(){
- if (Database.userGameCount > 5 && !Database.purchasedNoAds) {
- Appodeal.show (Appodeal.BANNER_TOP);
- _bannerIsVisible = true;
- return true;
- }
- _bannerIsVisible = false;
- return false;
- }
- public static void HideBanner(){
- _bannerIsVisible = false;
- Appodeal.hide (Appodeal.BANNER);
- }
- public static void ShowInterstitial(){
- if(Database.userGameCount>2 && timeSinceLastAd> 2 * 60 && !Database.purchasedNoAds){
- if(Appodeal.isLoaded(Appodeal.INTERSTITIAL)){
- timeOfLastAd = Time.time;
- Appodeal.show (Appodeal.INTERSTITIAL);
- }
- }
- }
- public static bool CanShowRewardedVideo(){
- return Appodeal.isLoaded (Appodeal.REWARDED_VIDEO);
- }
- public static void ShowRewardedVideo(){
- if(Appodeal.isLoaded(Appodeal.REWARDED_VIDEO)){
- Appodeal.show(Appodeal.REWARDED_VIDEO);
- timeOfLastAd = Time.time;
- }
- }
- #region IRewardedVideoAdListener implementation
- public void onRewardedVideoLoaded ()
- {
- }
- public void onRewardedVideoFailedToLoad ()
- {
- }
- public void onRewardedVideoShown ()
- {
- }
- public void onRewardedVideoFinished (int amount, string name)
- {
- GameSparksWrapper.WatchAd ();
- }
- public void onRewardedVideoClosed ()
- {
- }
- #endregion
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement