OneShotOneKill/Assets/Script/Info/ADInfo.cs

143 lines
4.6 KiB
C#

//using GoogleMobileAds.Api;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ADInfo : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod]
static void OnRuntimeMethodLoad() { new GameObject("ADInfo").AddComponent<ADInfo>(); }
public static ADInfo Ins;
//private RewardedAd rewardedAd;
byte GetReward = 0;
bool IsLoadingAD;
Action Action_success, Action_fail;
private void Awake()
{
Ins = this;
DontDestroyOnLoad(gameObject);
}
public void Start()
{
// // Initialize the Google Mobile Ads SDK.
// MobileAds.Initialize(initStatus => { });
//#if UNITY_ANDROID
// //rewardedAd = new RewardedAd("ca-app-pub-3940256099942544/5224354917"); // Android 테스트 광고 ID
// rewardedAd = new RewardedAd("ca-app-pub-1124323716421754/7125654939");
//#else
// //rewardedAd = new RewardedAd("ca-app-pub-3940256099942544/1712485313"); // IOS 테스트 광고 ID
// rewardedAd = new RewardedAd("ca-app-pub-1124323716421754/9240682382");
//#endif
// // Called when an ad request has successfully loaded.
// rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
// // Called when an ad request failed to load.
// rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
// // Called when an ad is shown.
// rewardedAd.OnAdOpening += HandleRewardedAdOpening;
// // Called when an ad request failed to show.
// rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
// // Called when the user should be rewarded for interacting with the ad.
// rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
// // Called when the ad is closed.
// rewardedAd.OnAdClosed += HandleRewardedAdClosed;
LoadAD();
}
void LoadAD()
{
if (IsLoadingAD) return;
IsLoadingAD = true;
//rewardedAd.LoadAd(new AdRequest.Builder().Build());
}
public void HandleRewardedAdLoaded(object sender, EventArgs args)
{
IsLoadingAD = false;
MonoBehaviour.print("HandleRewardedAdLoaded event received");
}
//private void HandleRewardedAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
//{
// IsLoadingAD = false;
// LoadAD();
// MonoBehaviour.print(
// "HandleRewardedAdFailedToLoad event received with message: "
// + e.LoadAdError.GetMessage());
//}
//public void HandleRewardedAdOpening(object sender, EventArgs args)
//{
// MonoBehaviour.print("HandleRewardedAdOpening event received");
//}
//public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args)
//{
// LoadAD();
// GetReward = 3;
//}
//public void HandleRewardedAdClosed(object sender, EventArgs args)
//{
// LoadAD();
// MonoBehaviour.print("HandleRewardedAdClosed event received");
//}
//public void HandleUserEarnedReward(object sender, Reward args)
//{
// LoadAD();
// GetReward = 1;
//}
public void Show_AD(Action _success, Action _fail = null)
{
Action_success = _success;
Action_fail = _fail;
GetReward = 0;
GetReward = 1;
//#if UNITY_EDITOR
// GetReward = 1;
//#else
// if (ServerInfo.Ins.m_ServerData.Get_Common(eCommon.ADRemove) == 1)
// GetReward = 1;
// else
// {
// //if (rewardedAd.IsLoaded())
// //{
// // rewardedAd.Show();
// // MobileAds.SetiOSAppPauseOnBackground(true);
// //}
// //else
// GetReward = 2;
// }
//#endif
}
private void Update()
{
switch (GetReward)
{
case 1:
GetReward = 0;
//MobileAds.SetiOSAppPauseOnBackground(false);
Action_success?.Invoke();
//var sdata = ServerInfo.Ins.m_ServerData;
//sdata.Add_MissionCount(ePurpose.WATCH_AD_ALL);
//sdata.Add_MissionCount(ePurpose.WATCH_AD_ACC);
break;
case 2:
GetReward = 0;
Popup.Ins.Set(ePopupType.One, 102);
Action_fail?.Invoke();
// MobileAds.SetiOSAppPauseOnBackground(false);
break;
case 3:
GetReward = 0;
Popup.Ins.Set(ePopupType.One, 103);
Action_fail?.Invoke();
//MobileAds.SetiOSAppPauseOnBackground(false);
break;
}
}
}