Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using UniRx;
- using UnityEngine;
- namespace ElectrumGames.Core.Mediation
- {
- public class AndroidAdsManager : IAdsManager, IDisposable
- {
- private const string AppKey = "1b9121145"; //is default - 85460dcd | my - 1b9121145 | cbh - 18895eccd
- private readonly IronSource _agent;
- private Action<bool> _cashedEvent;
- public bool InterstitialReady => _agent.isInterstitialReady();
- public bool RewardedVideoReady => _agent.isRewardedVideoAvailable();
- public AndroidAdsManager()
- {
- IronSourceConfig.Instance.setClientSideCallbacks(true);
- _agent = IronSource.Agent;
- _agent.validateIntegration();
- _agent.init(AppKey);
- IronSourceRewardedVideoEvents.onAdClosedEvent += OnSuccessfulRewardedVideoWatch;
- IronSourceRewardedVideoEvents.onAdShowFailedEvent += OnFailedRewardedVideoWatch;
- }
- public void Dispose()
- {
- IronSourceRewardedVideoEvents.onAdClosedEvent -= OnSuccessfulRewardedVideoWatch;
- IronSourceRewardedVideoEvents.onAdShowFailedEvent -= OnFailedRewardedVideoWatch;
- }
- public void LoadAds()
- {
- Observable.FromCoroutine(InterstitialLoadProcess).Subscribe();
- Observable.FromCoroutine(RewardedVideoLoadProcess).Subscribe();
- }
- public bool TryShowInterstitial()
- {
- if (!InterstitialReady)
- {
- Observable.FromCoroutine(InterstitialLoadProcess).Subscribe();
- return false;
- }
- _agent.showInterstitial();
- Observable.FromCoroutine(InterstitialLoadProcess).Subscribe();
- return true;
- }
- public bool TryShowRewardedVideo(Action<bool> onComplete)
- {
- if (!RewardedVideoReady)
- {
- Observable.FromCoroutine(RewardedVideoLoadProcess).Subscribe();
- return false;
- }
- _cashedEvent = onComplete;
- _agent.showRewardedVideo();
- Observable.FromCoroutine(RewardedVideoLoadProcess).Subscribe();
- return true;
- }
- private IEnumerator InterstitialLoadProcess()
- {
- while (!InterstitialReady)
- {
- _agent.loadInterstitial();
- yield return new WaitForEndOfFrame();
- }
- }
- private IEnumerator RewardedVideoLoadProcess()
- {
- while (!RewardedVideoReady)
- {
- _agent.loadRewardedVideo();
- yield return new WaitForEndOfFrame();
- }
- }
- private void OnSuccessfulRewardedVideoWatch(IronSourceAdInfo info)
- {
- _cashedEvent?.Invoke(true);
- }
- private void OnFailedRewardedVideoWatch(IronSourceError error, IronSourceAdInfo info)
- {
- _cashedEvent?.Invoke(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement