Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using UnityEngine;
- using UnityEngine.Advertisements;
- namespace GibbestBow.Ads
- {
- public class UnityAdsNetwork : AdNetwork, IUnityAdsListener
- {
- const string UNITY_ADS_GAME_ID_ANDROID = "2596860";
- const string UNITY_ADS_GAME_ID_IOS = "2596861";
- Action<ShowResult> onRewardedVideo;
- public override bool GetState(string placementId, AdsType adsType)
- {
- return Advertisement.IsReady(placementId); // Any type
- }
- public override void Init()
- {
- NetworkType = AdNetworks.UnityAds;
- IncludeInterstitial = true;
- IncludeRewardVideo = true;
- if (!Advertisement.isSupported)
- return;
- if (Application.platform == RuntimePlatform.Android)
- Advertisement.Initialize(UNITY_ADS_GAME_ID_ANDROID, Constants.DEBUG_MODE);
- else if (Application.platform == RuntimePlatform.IPhonePlayer)
- Advertisement.Initialize(UNITY_ADS_GAME_ID_IOS, Constants.DEBUG_MODE);
- else
- Advertisement.Initialize(UNITY_ADS_GAME_ID_ANDROID, true);
- Subscribe();
- }
- public override bool ShowInterstitial(string placementId)
- {
- Debug.Log("Unity ads ShowInterstitial");
- onRewardedVideo = null;
- if (!Advertisement.isInitialized)
- {
- return false;
- }
- if (Advertisement.IsReady(placementId))
- {
- DNSoundManager.GetInstance().Pause();
- if (GameData.GetInstance().GetCanShowIap())
- {
- GameData.GetInstance().SetShowIap(true);
- }
- try
- {
- Advertisement.Show(placementId);
- }
- catch
- {
- }
- return true;
- }
- else
- {
- return false;
- }
- }
- public override bool ShowRewardedVideo(Action<ShowResult> callback, string placementId)
- {
- Debug.Log("Unity ads ShowRewardedVideo");
- if (!Advertisement.isInitialized)
- return false;
- if (!Advertisement.IsReady(placementId))
- return false;
- onRewardedVideo = callback;
- DNSoundManager.GetInstance().Pause();
- try
- {
- Advertisement.Show(placementId);
- }
- catch
- {
- }
- return true;
- }
- public override void Subscribe()
- {
- Debug.Log("Unity ads Subscribe");
- Advertisement.AddListener(this);
- }
- public override void UnSubscribe()
- {
- try
- {
- DNSoundManager.GetInstance().Unpause();
- }
- catch
- {
- Debug.LogWarning("Some error in Unpause method");
- }
- Debug.Log("Unity ads UnSubscribe");
- Advertisement.RemoveListener(this);
- }
- public void OnUnityAdsDidError(string message)
- {
- try
- {
- DNSoundManager.GetInstance().Unpause();
- }
- catch
- {
- Debug.LogWarning("Some error in Unpause method");
- }
- Debug.Log("Unity ads OnUnityAdsDidError");
- onRewardedVideo?.Invoke(ShowResult.Failed);
- }
- public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
- {
- try
- {
- DNSoundManager.GetInstance().Unpause();
- }
- catch
- {
- Debug.LogWarning("Some error in Unpause method");
- }
- Debug.Log("Unity ads OnUnityAdsDidFinish");
- onRewardedVideo?.Invoke(showResult);
- }
- public void OnUnityAdsDidStart(string placementId)
- {
- }
- public void OnUnityAdsReady(string placementId)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement