2025-09-15 21:10:41 +00:00
|
|
|
using GoogleMobileAds.Api;
|
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
2025-09-15 21:41:59 +00:00
|
|
|
public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>
|
2025-09-15 21:10:41 +00:00
|
|
|
{
|
2025-09-15 21:41:59 +00:00
|
|
|
//[RuntimeInitializeOnLoadMethod]
|
|
|
|
|
//static void OnRuntimeMethodLoad() { new GameObject("ADInfo").AddComponent<ADInfo>(); }
|
2025-09-15 21:10:41 +00:00
|
|
|
|
2025-09-15 21:41:59 +00:00
|
|
|
//public static ADInfo Ins;
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
private RewardedInterstitialAd short_rewardedInterstitialAd;
|
2025-09-23 23:36:55 +00:00
|
|
|
//string rewardedInterstitialAd_ID = "ca-app-pub-6390804219581974/3468554834";
|
|
|
|
|
string rewardedInterstitialAd_ID = "ca-app-pub-3940256099942544/1033173712"; // 테스트
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
private InterstitialAd m_interstitialAd;
|
2025-09-23 23:36:55 +00:00
|
|
|
//string InterstitialAd_ID = "ca-app-pub-2550554896492831/9309815439";
|
|
|
|
|
string InterstitialAd_ID = "ca-app-pub-3940256099942544/1033173712"; // 테스트
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
private RewardedAd long_rewardedAd;
|
2025-09-23 23:36:55 +00:00
|
|
|
//string longAD = "ca-app-pub-2550554896492831/2536577422";
|
|
|
|
|
string longAD = "ca-app-pub-3940256099942544/5224354917"; // 테스트
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
BannerView _bannerView;
|
2025-09-23 23:36:55 +00:00
|
|
|
//string bannerAD = "ca-app-pub-2550554896492831/2225586237";
|
|
|
|
|
string bannerAD = "ca-app-pub-3940256099942544/6300978111"; // 테스트
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
byte GetReward = 0;
|
|
|
|
|
Action Action_success, Action_fail;
|
|
|
|
|
bool isLoading_InterstitialAd, isLoading_RewardedAd;
|
|
|
|
|
|
2025-09-15 21:41:59 +00:00
|
|
|
//private void Awake()
|
|
|
|
|
//{
|
|
|
|
|
// Ins = this;
|
|
|
|
|
// DontDestroyOnLoad(gameObject);
|
|
|
|
|
//}
|
2025-09-15 21:10:41 +00:00
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
MobileAds.Initialize(initStatus =>
|
|
|
|
|
{
|
|
|
|
|
//Load_RewardedInterstitialAd(rewardedInterstitialAd_ID, Set_RewardedInterstitialAd);
|
|
|
|
|
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
|
|
|
|
|
Load_LongAD(longAD, Set_LongAD);
|
2025-09-16 20:39:37 +00:00
|
|
|
|
|
|
|
|
AdSize adaptiveSize = AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
|
|
|
|
|
_bannerView = new BannerView(bannerAD, adaptiveSize, AdPosition.Bottom);
|
2025-09-15 21:10:41 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_RewardedInterstitialAd(RewardedInterstitialAd ad)
|
|
|
|
|
{
|
|
|
|
|
if (short_rewardedInterstitialAd != null)
|
|
|
|
|
{
|
|
|
|
|
short_rewardedInterstitialAd.Destroy();
|
|
|
|
|
short_rewardedInterstitialAd = null;
|
|
|
|
|
}
|
|
|
|
|
short_rewardedInterstitialAd = ad;
|
|
|
|
|
}
|
|
|
|
|
void Set_InterstitialAd(InterstitialAd ad)
|
|
|
|
|
{
|
|
|
|
|
if (m_interstitialAd != null)
|
|
|
|
|
{
|
|
|
|
|
m_interstitialAd.Destroy();
|
|
|
|
|
m_interstitialAd = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_interstitialAd = ad;
|
|
|
|
|
|
|
|
|
|
m_interstitialAd.OnAdFullScreenContentClosed += () =>
|
|
|
|
|
{
|
|
|
|
|
GetReward = 1;
|
|
|
|
|
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
m_interstitialAd.OnAdFullScreenContentFailed += (AdError adError) =>
|
|
|
|
|
{
|
|
|
|
|
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
void Set_LongAD(RewardedAd ad)
|
|
|
|
|
{
|
|
|
|
|
if (long_rewardedAd != null)
|
|
|
|
|
{
|
|
|
|
|
long_rewardedAd.Destroy();
|
|
|
|
|
long_rewardedAd = null;
|
|
|
|
|
}
|
|
|
|
|
long_rewardedAd = ad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Load_RewardedInterstitialAd(string s_ad, Action<RewardedInterstitialAd> adaction)
|
|
|
|
|
{
|
|
|
|
|
// create our request used to load the ad.
|
|
|
|
|
var adRequest = new AdRequest();
|
|
|
|
|
|
|
|
|
|
// send the request to load the ad.
|
|
|
|
|
RewardedInterstitialAd.Load(s_ad, adRequest,
|
|
|
|
|
(RewardedInterstitialAd ad, LoadAdError error) =>
|
|
|
|
|
{
|
|
|
|
|
// if error is not null, the load request failed.
|
|
|
|
|
if (error != null || ad == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Rewarded ad failed to load an ad " +
|
|
|
|
|
"with error : " + error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adaction(ad);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
void Load_InterstitialAd(string s_ad, Action<InterstitialAd> adaction)
|
|
|
|
|
{
|
|
|
|
|
if (isLoading_InterstitialAd) return;
|
|
|
|
|
isLoading_InterstitialAd = true;
|
|
|
|
|
|
|
|
|
|
// create our request used to load the ad.
|
|
|
|
|
var adRequest = new AdRequest();
|
|
|
|
|
|
|
|
|
|
// send the request to load the ad.
|
|
|
|
|
InterstitialAd.Load(s_ad, adRequest,
|
|
|
|
|
(InterstitialAd ad, LoadAdError error) =>
|
|
|
|
|
{
|
|
|
|
|
isLoading_InterstitialAd = false;
|
|
|
|
|
|
|
|
|
|
// if error is not null, the load request failed.
|
|
|
|
|
if (error != null || ad == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Rewarded ad failed to load an ad " +
|
|
|
|
|
"with error : " + error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adaction(ad);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
void Load_LongAD(string s_ad, Action<RewardedAd> adaction)
|
|
|
|
|
{
|
|
|
|
|
if (isLoading_RewardedAd) return;
|
|
|
|
|
isLoading_RewardedAd = true;
|
|
|
|
|
|
|
|
|
|
// create our request used to load the ad.
|
|
|
|
|
var adRequest = new AdRequest();
|
|
|
|
|
|
|
|
|
|
// send the request to load the ad.
|
|
|
|
|
RewardedAd.Load(s_ad, adRequest,
|
|
|
|
|
(RewardedAd ad, LoadAdError error) =>
|
|
|
|
|
{
|
|
|
|
|
isLoading_RewardedAd = false;
|
|
|
|
|
|
|
|
|
|
// if error is not null, the load request failed.
|
|
|
|
|
if (error != null || ad == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Rewarded ad failed to load an ad " +
|
|
|
|
|
"with error : " + error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
adaction(ad);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Show_AD(bool bshort, Action _success, Action _fail = null)
|
|
|
|
|
{
|
|
|
|
|
Stop_Game();
|
|
|
|
|
|
|
|
|
|
Action_success = _success;
|
|
|
|
|
Action_fail = _fail;
|
|
|
|
|
GetReward = 0;
|
|
|
|
|
|
|
|
|
|
if (bshort)
|
|
|
|
|
{
|
2025-09-21 22:09:32 +00:00
|
|
|
if (SaveMgr.Ins.Get_ShopAD()) // 리워드형 광고가 아니면 제거
|
|
|
|
|
{
|
|
|
|
|
GetReward = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 21:10:41 +00:00
|
|
|
if (m_interstitialAd != null && m_interstitialAd.CanShowAd())
|
|
|
|
|
{
|
|
|
|
|
m_interstitialAd.Show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GetReward = 2;
|
|
|
|
|
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (long_rewardedAd != null && long_rewardedAd.CanShowAd())
|
|
|
|
|
{
|
|
|
|
|
long_rewardedAd.Show((Reward reward) =>
|
|
|
|
|
{
|
|
|
|
|
GetReward = 1;
|
|
|
|
|
Load_LongAD(longAD, Set_LongAD);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GetReward = 2;
|
|
|
|
|
Load_LongAD(longAD, Set_LongAD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 21:41:59 +00:00
|
|
|
protected override void Update()
|
2025-09-15 21:10:41 +00:00
|
|
|
{
|
2025-09-15 21:41:59 +00:00
|
|
|
base.Update();
|
2025-09-15 21:10:41 +00:00
|
|
|
switch (GetReward)
|
|
|
|
|
{
|
|
|
|
|
case 1:
|
|
|
|
|
GetReward = 0;
|
|
|
|
|
Play_Game();
|
|
|
|
|
Action_success?.Invoke(); // 후 처리 및 저장
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
GetReward = 0;
|
|
|
|
|
Play_Game();
|
|
|
|
|
LobbyUI.Ins.m_ToastUI.Set("준비된 광고가 없습니다.\n나중에 다시 시도해 주세요.");
|
|
|
|
|
Action_fail?.Invoke();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
GetReward = 0;
|
|
|
|
|
Play_Game();
|
|
|
|
|
LobbyUI.Ins.m_ToastUI.Set("준비된 광고가 없습니다.\n나중에 다시 시도해 주세요.");
|
|
|
|
|
Action_fail?.Invoke();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float curVolume;
|
|
|
|
|
void Stop_Game()
|
|
|
|
|
{
|
|
|
|
|
//Time.timeScale = 0f;
|
|
|
|
|
curVolume = AudioListener.volume;
|
|
|
|
|
AudioListener.volume = 0f;
|
|
|
|
|
}
|
|
|
|
|
void Play_Game()
|
|
|
|
|
{
|
|
|
|
|
//Time.timeScale = 1f;
|
|
|
|
|
AudioListener.volume = curVolume;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Set_Banner(bool active)
|
|
|
|
|
{
|
|
|
|
|
if (_bannerView == null) return;
|
|
|
|
|
|
|
|
|
|
if (active)
|
|
|
|
|
{
|
2025-09-16 20:39:37 +00:00
|
|
|
//// 배너 광고 요청 및 표시
|
|
|
|
|
//var adRequest = new AdRequest();
|
|
|
|
|
//_bannerView.LoadAd(adRequest);
|
2025-09-21 22:03:42 +00:00
|
|
|
if (!SaveMgr.Ins.Get_ShopAD())
|
|
|
|
|
_bannerView.Show();
|
2025-09-15 21:10:41 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_bannerView.Hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|