| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System;
- using UnityEngine;
- namespace HexaCrazy.Ads
- {
- public enum RewardedAdStatus { Preparing, Loading, Ready, NetworkError, NoFill, LoadFailed, PrivacyUnavailable }
- public abstract class RewardedAds : MonoBehaviour
- {
- public RewardedAdStatus Status { get; protected set; } = RewardedAdStatus.Preparing;
- public virtual void Retry() { }
- public abstract bool Supported { get; }
- public virtual bool NeedsPrivacyOptions => false;
- public virtual void ShowPrivacyOptions() { }
- public bool IsShowing { get; private set; }
- // The provider calls both delegates on Unity's main thread. A closed
- // impression can never award a later impression's reward.
- public bool TryShow(Action onEarned, Action<bool> onClosed)
- {
- if (IsShowing || !Supported) return false;
- IsShowing = true;
- bool earned = false, ended = false;
- void Earn()
- {
- if (earned || ended) return;
- earned = true;
- onEarned?.Invoke();
- }
- void Close()
- {
- if (ended) return;
- ended = true;
- IsShowing = false;
- onClosed(earned);
- }
- if (Present(Earn, Close)) return true;
- ended = true;
- IsShowing = false;
- return false;
- }
- protected abstract bool Present(Action earn, Action close);
- }
- }
|