104 lines
2.2 KiB
C#
104 lines
2.2 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using RND.Mediation;
|
|
using System.Globalization;
|
|
|
|
public static class Ads
|
|
{
|
|
public delegate void FailFunc();
|
|
public delegate void RewardFunc();
|
|
public delegate void CloseFunk();
|
|
|
|
public static RewardFunc GetReward;
|
|
public static FailFunc GetFail;
|
|
public static CloseFunk GetClose;
|
|
|
|
public static event Action OnRemoveAdsStateChanged;
|
|
|
|
private static bool _isInitialized;
|
|
private static IAdsSDK _sdk = new NullAdsSDK();
|
|
private const string ADS_REMOVED = "ads_removed";
|
|
|
|
public static bool AdsIsRemoved
|
|
{
|
|
get => AdsRemovedGet();
|
|
set
|
|
{
|
|
AdsRemovedSet(value);
|
|
OnRemoveAdsStateChanged?.Invoke();
|
|
}
|
|
}
|
|
|
|
public static void Init()
|
|
{
|
|
LoadSDK();
|
|
}
|
|
|
|
private static void LoadSDK()
|
|
{
|
|
#if RND_MOPUB
|
|
_sdk = new MoPubSDK();
|
|
#elif RND_MAX
|
|
_sdk = new MaxSDK();
|
|
#endif
|
|
|
|
_sdk.Init(OnSdkInitialized);
|
|
}
|
|
|
|
private static bool AdsRemovedGet()
|
|
{
|
|
if (PlayerPrefs.HasKey(ADS_REMOVED) == false)
|
|
AdsRemovedSet(false);
|
|
|
|
return PlayerPrefs.GetInt(ADS_REMOVED) == 1;
|
|
}
|
|
|
|
private static void AdsRemovedSet(bool value)
|
|
{
|
|
PlayerPrefs.SetInt(ADS_REMOVED, value ? 1 : 0);
|
|
}
|
|
|
|
public static bool HasRewardVideo()
|
|
{
|
|
return _sdk.HasRewardVideo();
|
|
}
|
|
|
|
public static bool HasInterstitialVideo()
|
|
{
|
|
return _sdk.HasInterstitialVideo();
|
|
}
|
|
|
|
public static void ShowBanner()
|
|
{
|
|
if (!_isInitialized || AdsIsRemoved)
|
|
return;
|
|
|
|
_sdk.ShowBanner();
|
|
}
|
|
|
|
public static void ShowInterstitial(string placement)
|
|
{
|
|
if (!_isInitialized || AdsIsRemoved)
|
|
return;
|
|
|
|
_sdk.ShowInterstitial();
|
|
}
|
|
|
|
public static void ShowReward(string placement, RewardFunc reward, FailFunc fail, RewardFunc closed = null)
|
|
{
|
|
GetReward = reward;
|
|
GetFail = fail;
|
|
|
|
if (!_isInitialized || AdsIsRemoved)
|
|
return;
|
|
|
|
_sdk.ShowReward();
|
|
}
|
|
|
|
private static void OnSdkInitialized()
|
|
{
|
|
_isInitialized = true;
|
|
Log.Debug("Ads: Manager is initialized");
|
|
}
|
|
}
|