You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
278 lines
6.6 KiB
278 lines
6.6 KiB
using IVDataFormat;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
|
|
public class AdsMgr : MonoBehaviour
|
|
{
|
|
#region Variables
|
|
protected const int I_RETRY = 0;
|
|
|
|
public const int PlatformAdMob = 0;
|
|
public const int PlatformUnityAds = 1;
|
|
public const int PlatformIronSource = 3;
|
|
|
|
public const string ZoneBase = "rewarded_video";
|
|
|
|
public enum eAdsFinish
|
|
{
|
|
Fail = 0,
|
|
Skip = 1,
|
|
Success = 2,
|
|
Loading = -1
|
|
}
|
|
|
|
public enum eRewardType
|
|
{
|
|
None = 0,
|
|
Shop = 1,
|
|
Buff = 2
|
|
}
|
|
|
|
public static bool B_ADS_CLICK = false;
|
|
public static bool B_ADS_REWARD { get; set; }
|
|
public static bool B_ADS_CLOSE { get; set; }
|
|
|
|
private static AdsMgr curMgr = null;
|
|
|
|
private static eRewardType rewardType = eRewardType.None;
|
|
private static int rewardId = -1;
|
|
#endregion Variables
|
|
|
|
#region Base
|
|
private void Awake()
|
|
{
|
|
if (curMgr != null)
|
|
{
|
|
Destroy(this.gameObject);
|
|
return;
|
|
}
|
|
curMgr = this;
|
|
DontDestroyOnLoad(this.gameObject);
|
|
}
|
|
|
|
|
|
public static void SForceStopCoroutines()
|
|
{
|
|
if (curMgr != null)
|
|
curMgr.StopAllCoroutines();
|
|
}
|
|
|
|
|
|
public static void SInit()
|
|
{
|
|
if (curMgr != null)
|
|
curMgr.Init();
|
|
}
|
|
|
|
|
|
private void Init()
|
|
{
|
|
#if ADS_ENABLE
|
|
#if ADS_ADMOB
|
|
AdMobMgr.Instance.InitAdsMgr(this);
|
|
#elif ADS_IRON
|
|
IronSourceMgr.Instance.InitAdsMgr(this);
|
|
#elif ADS_UNITY
|
|
UnityAdsMgr.Instance.InitAdsMgr(this);
|
|
#endif
|
|
#endif
|
|
}
|
|
|
|
// 광고 재생 횟수 추가.
|
|
protected void AddAdsCnt()
|
|
{
|
|
//DataHandler.AddRecord(eCondition.AdPlay);
|
|
//QuestMgr.
|
|
//MissionMgr.
|
|
}
|
|
#endregion Base
|
|
|
|
|
|
#region Play Rewarded Video Ads
|
|
public static void SPlayRewardAds(eRewardType rewtype, int irewid)
|
|
{
|
|
curMgr.PlayRewardAds(rewtype, irewid);
|
|
}
|
|
|
|
// 보상형 광고 재생.
|
|
private void PlayRewardAds(eRewardType rewtype, int irewid)
|
|
{
|
|
//Debug.Log("ShowRewardAds");
|
|
B_ADS_CLICK = false;
|
|
B_ADS_REWARD = false;
|
|
B_ADS_CLOSE = false;
|
|
|
|
rewardType = rewtype;
|
|
rewardId = irewid;
|
|
|
|
if (Application.internetReachability == NetworkReachability.NotReachable)
|
|
{
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Fail, false));
|
|
GameUIMgr.SOpenPopup1Button(LocalizationText.GetText(Global.STR_CheckNetwork));
|
|
return;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Success, true));
|
|
#elif !ADS_ENABLE
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Success, true));
|
|
#else
|
|
// 광고 제거.
|
|
if (DataHandler.PlayData.adsRemove)
|
|
{
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Success, true));
|
|
return;
|
|
}
|
|
|
|
// 재생 가능한 광고.
|
|
if (!GetAdsAvailable())
|
|
{
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Fail, false));
|
|
return;
|
|
}
|
|
|
|
#if ADS_ADMOB
|
|
SingleMgr.Instance.SetAdsPause(true);
|
|
SettingMgr.SMasterSoundOff();
|
|
AdMobMgr.Instance.ShowRewardVideo();
|
|
#elif ADS_IRON
|
|
SingleMgr.Instance.SetAdsPause(true);
|
|
SettingMgr.SMasterSoundOff();
|
|
IronSourceMgr.Instance.ShowRewardVideo();
|
|
#elif ADS_UNITY
|
|
SingleMgr.Instance.SetAdsPause(true);
|
|
SettingMgr.SMasterSoundOff();
|
|
UnityAdsMgr.Instance.ShowAds();
|
|
#else
|
|
SingleMgr.Instance.SetAdsPause(false);
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Fail, false));
|
|
#endif
|
|
|
|
#endif
|
|
}
|
|
|
|
// 보상형 광고 재생 가능 상태.
|
|
private bool GetAdsAvailable()
|
|
{
|
|
#if UNITY_EDITOR
|
|
return false;
|
|
#elif !ADS_ENABLE
|
|
return false;
|
|
#else
|
|
if (Application.internetReachability.Equals(NetworkReachability.NotReachable))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
#if ADS_ADMOB
|
|
return AdMobMgr.GetAdsAvailable();
|
|
#elif ADS_IRON
|
|
return IronSourceMgr.GetAdsAvailable();
|
|
#elif ADS_UNITY
|
|
return UnityAdsMgr.GetAdsAvailable();
|
|
#endif
|
|
return false;
|
|
#endif
|
|
}
|
|
#endregion Play Rewarded Video Ads
|
|
|
|
|
|
#region Invoke Ads Finished
|
|
// AdMob의 경우 광고 닫고 바로 체크하면 크래시 현상이 발생하므로 0.3초 딜레이 후 처리.
|
|
public void InvokeAdsRew()
|
|
{
|
|
B_ADS_REWARD = true;
|
|
}
|
|
|
|
|
|
public void InvokeAdsClose()
|
|
{
|
|
B_ADS_CLOSE = true;
|
|
Invoke("CheckAdsFinished", 0.3f * Time.timeScale);
|
|
}
|
|
|
|
|
|
public void InvokeAdsFinishFail()
|
|
{
|
|
B_ADS_REWARD = false;
|
|
B_ADS_CLOSE = false;
|
|
Invoke("OnAdsFinishedFail", 0.3f * Time.timeScale);
|
|
}
|
|
|
|
|
|
protected void CheckAdsFinished()
|
|
{
|
|
if (!B_ADS_CLOSE)
|
|
return;
|
|
B_ADS_CLOSE = false;
|
|
if (B_ADS_REWARD)
|
|
{
|
|
B_ADS_REWARD = false;
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Success, true));
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Skip, true));
|
|
}
|
|
}
|
|
|
|
|
|
protected void OnAdsFinishedFail()
|
|
{
|
|
StartCoroutine(OnAdsFinished(eAdsFinish.Fail, true));
|
|
}
|
|
#endregion Invoke Ads Finished
|
|
|
|
|
|
// 보상형 광고 종료시 처리.
|
|
public IEnumerator OnAdsFinished(eAdsFinish eads, bool bshowreal)
|
|
{
|
|
//Debug.Log("OnAdsFinished");
|
|
SingleMgr.Instance.SetAdsPause(true);
|
|
//@ 광고 종료 후 다시 인게임 사운드 켜기.
|
|
//SettingMgr.SMasterSoundOn();
|
|
yield return null;
|
|
|
|
// 광고 재생 완료.
|
|
if (eads == eAdsFinish.Success)
|
|
{
|
|
if (bshowreal)
|
|
AddAdsCnt();
|
|
switch (rewardType)
|
|
{
|
|
case eRewardType.Shop:
|
|
ShopMgr.SSubProcessSucc(rewardId);
|
|
break;
|
|
}
|
|
if (bshowreal)
|
|
{
|
|
AnalyticsMgr.EventCompAds();
|
|
if (B_ADS_CLICK)
|
|
AnalyticsMgr.EventClickAds();
|
|
}
|
|
}
|
|
// 광고 재생 실패.
|
|
else if (eads == eAdsFinish.Fail)
|
|
{
|
|
switch (rewardType)
|
|
{
|
|
case eRewardType.Shop:
|
|
ShopMgr.SSubProcessFail(rewardId);
|
|
break;
|
|
}
|
|
GameUIMgr.SOpenToast(LocalizationText.GetText("error_adsfail"));
|
|
}
|
|
// 광고 스킵.
|
|
else
|
|
{
|
|
switch (rewardType)
|
|
{
|
|
case eRewardType.Shop:
|
|
ShopMgr.SSubProcessFail(rewardId);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|