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.
 
 
 
 
 
 

260 lines
6.8 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
#endif
public class IronSourceMgr : MonoBehaviour
{
#region Instance
private static IronSourceMgr _instance;
public static IronSourceMgr Instance
{
get
{
if (_instance == null)
{
_instance = FindObjectOfType(typeof(IronSourceMgr)) as IronSourceMgr;
if (_instance == null)
{
_instance = (new GameObject("IronSourceMgr")).AddComponent<IronSourceMgr>();
}
}
return _instance;
}
}
#endregion
#region Variables
protected static bool B_INIT = false;
protected static bool B_PLAYING = false;
protected static bool B_OPEN = false;
protected static bool B_CLOSE = false;
protected static bool B_REWARD = false;
protected static bool B_Ready = false;
#if UNITY_ANDROID
public const string AppKey = "12f2ded1d";
public const string RewardInstanceId = "7056691";
public const string RewardPlacementName = "aos_rewarded_video";
#elif UNITY_IOS
public const string AppKey = "12f2e99b5";
public const string RewardInstanceId = "7056769";
public const string RewardPlacementName = "ios_rewarded_video";
#else
public const string AdRewardUnitId6 = "unexpected_platform";
public const string RewardInstanceId = "unexpected_platform";
public const string RewardPlacementName = "DefaultRewardedVideo";
#endif
protected static AdsMgr adsMgr;
#endregion Variables
void Awake()
{
DontDestroyOnLoad(gameObject);
}
void OnApplicationPause(bool pause)
{
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
IronSource.Agent.onApplicationPause(pause);
if (!pause && B_INIT)
{
Invoke("CheckPause1", 0.3f);
}
#endif
}
public void InitAdsMgr(AdsMgr adsmgr)
{
adsMgr = adsmgr;
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
if (!B_INIT)
{
B_INIT = true;
IronSourceConfig.Instance.setClientSideCallbacks(true);
if (DataMgr.IsGDPR && !DataMgr.IsGDPRAgree)
{
IronSource.Agent.setConsent(true);
}
IronSource.Agent.setMetaData("is_child_directed", "false"); // 어린이 사용자 아님.
//IronSource.Agent.setMetaData("do_not_sell", "false"); // CCPA 허용
IronSource.Agent.shouldTrackNetworkState(true);
IronSource.Agent.init(AppKey, IronSourceAdUnits.REWARDED_VIDEO);
InitRewardVideo();
}
#endif
}
public void CheckPause1()
{
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
if (!B_Ready && !B_PLAYING)
{
//Debug.Log("Iron - CheckPause1");
IronSource.Agent.onApplicationPause(false);
Invoke("CheckPause2", 0.3f);
}
#endif
}
public void CheckPause2()
{
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
if (!B_Ready && !B_PLAYING)
{
//Debug.Log("Iron - CheckPause2");
IronSource.Agent.init(AppKey, IronSourceAdUnits.REWARDED_VIDEO);
}
#endif
}
public void CheckIntegration()
{
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
IronSource.Agent.validateIntegration();
#endif
}
#region Init
protected void InitRewardVideo()
{
if (!B_INIT)
return;
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
Debug.Log("Iron - InitRewardVideo");
IronSourceEvents.onRewardedVideoAdOpenedEvent += onRewardedVideoAdOpenedEvent;
IronSourceEvents.onRewardedVideoAdClickedEvent += onRewardedVideoAdClickedEvent;
IronSourceEvents.onRewardedVideoAdClosedEvent += onRewardedVideoAdClosedEvent;
IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += onRewardedVideoAvailabilityChangedEvent;
IronSourceEvents.onRewardedVideoAdStartedEvent += onRewardedVideoAdStartedEvent;
IronSourceEvents.onRewardedVideoAdEndedEvent += onRewardedVideoAdEndedEvent;
IronSourceEvents.onRewardedVideoAdRewardedEvent += onRewardedVideoAdRewardedEvent;
IronSourceEvents.onRewardedVideoAdShowFailedEvent += onRewardedVideoAdShowFailedEvent;
#endif
}
#endregion Init
#region Delegate
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
private void onRewardedVideoAvailabilityChangedEvent(bool obj)
{
Debug.Log("Iron - onRewardedVideoAvailabilityChangedEvent : " + obj);
B_Ready = obj;
}
private void onRewardedVideoAdOpenedEvent()
{
if (B_OPEN)
return;
B_OPEN = true;
B_PLAYING = true;
B_CLOSE = false;
B_REWARD = false;
Debug.Log("Iron - onRewardedVideoAdOpenedEvent");
}
private void onRewardedVideoAdStartedEvent()
{
//Debug.Log("Iron - onRewardedVideoAdStartedEvent");
}
private void onRewardedVideoAdEndedEvent()
{
//Debug.Log("Iron - onRewardedVideoAdEndedEvent");
}
private void onRewardedVideoAdClosedEvent()
{
if (B_CLOSE)
return;
B_CLOSE = true;
Debug.Log("Iron - onRewardedVideoAdClosedEvent");
if (B_PLAYING)
B_PLAYING = false;
if (adsMgr != null)
adsMgr.InvokeAdsClose();
Invoke("CheckPause1", 0.4f);
}
private void onRewardedVideoAdClickedEvent(IronSourcePlacement obj)
{
Debug.Log("Iron - onRewardedVideoAdClickedEvent");
}
private void onRewardedVideoAdRewardedEvent(IronSourcePlacement obj)
{
if (B_REWARD)
return;
B_REWARD = true;
B_PLAYING = false;
if (adsMgr != null)
adsMgr.InvokeAdsRew();
Debug.Log("Iron - onRewardedVideoAdRewardedEvent");
}
private void onRewardedVideoAdShowFailedEvent(IronSourceError obj)
{
Debug.Log("Iron - onRewardedVideoAdShowFailedEvent");
if (adsMgr != null)
{
adsMgr.InvokeAdsFinishFail();
}
}
#endif
#endregion Delegate
public void ShowRewardVideo()
{
#if ADS_ENABLE && ADS_IRON && (UNITY_ANDROID || UNITY_IOS)
B_PLAYING = true;
B_OPEN = false;
B_CLOSE = false;
B_REWARD = false;
IronSource.Agent.showRewardedVideo(RewardPlacementName);
#endif
}
public static bool GetAdsAvailable()
{
#if UNITY_EDITOR || !ADS_ENABLE || !ADS_IRON
return false;
#else
if (!B_INIT)
return false;
if (!B_Ready)
return false;
if (!B_PLAYING)
{
IronSource.Agent.onApplicationPause(false);
return false;
}
return true;
#endif
}
}