mergemilitary/Assets/TKGSDK/UnitySDK/Scripts/ADSScripts/ToukaSDK/Tools/AutoIntersititialManager.cs

95 lines
3.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Touka
{
public class AutoIntersititialManager : TGSingleton<AutoIntersititialManager>
{
public const string hasUploadEvent = "hasUploadEvent";
public int InterstitialShowCount = 0;
private TimerCounter t;
private bool mIsActive = false;
private int mRetryCount = 0;
private const int MAX_RETRY = 10;
public void Init()
{
mRetryCount = 0;
}
public override void Initialize()
{
base.Initialize();
t = gameObject.AddComponent<TimerCounter>();
t.StartTimer(AutoShowIntersititial, 3, int.MaxValue);
ActiveLogic(false);
t.PauseTimer(true);
}
public void ActiveLogic(bool pIsActive)
{
mIsActive = pIsActive;
t.PauseTimer(!pIsActive);
}
public void PauseTimer(bool pPause)
{
if (mIsActive)
{
t.PauseTimer(pPause);
}
}
#region
public void AutoShowIntersititial()
{
//1.支持在线参数控制自动插屏方案开关本地默认关闭在线参数为1则打开0则关闭
int autoShowIVSwitch = TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IVSwitch_OnlineParam.ToString(), 0);
LogEvent();
if (autoShowIVSwitch == 0)
{
Debug.Log("Check auto iv :" + autoShowIVSwitch);
mRetryCount++;
if (mRetryCount >= MAX_RETRY)
{
t.CancelTimer();
}
return;
}
//3.支持在线参数控制用户每次打开游戏展示N次插屏后才启用自动插屏逻辑若N = 0则代表每次打开都直接启用该逻辑本地默认N = 1
int ivShowCounts = TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IV_Counts_OnlineParam.ToString(), 1);
if (ivShowCounts == 0 || InterstitialShowCount >= ivShowCounts)
{
CanAutoShowIntersititial();
}
}
private void LogEvent()
{
int hasLogged = ToukaUtils.GetPlayerPrefsIntByKey(hasUploadEvent);
if (hasLogged != 10000)
{
string eventValue = string.Format("{0}_{1}_{2}", TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IVSwitch_OnlineParam.ToString(), 0), TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IV_Counts_OnlineParam.ToString(), 1), TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IV_MinTime_OnlineParam.ToString(), 30));
ToukaSDKManager.Instance.LogEventByUmeng("Autoiv", StaticStringsEvent.Event_Type_TKInner_ad_position, eventValue);
ToukaUtils.SavePlayerPrefsIntByKeyValue(hasUploadEvent, 10000);
}
}
private void CanAutoShowIntersititial()
{
float ivIntervalTime = TKGSDKManager.Instance.GetConfigInt(ToukaInnerParamKey.Auto_Show_IV_MinTime_OnlineParam.ToString(), 30);
float timeS = Time.time - ToukaInterstitialTimer.Instance.startedTime;
bool canShowFlg = timeS > ivIntervalTime;
if (canShowFlg)
{
t.PauseTimer(true);
TKGSDKManager.Instance.PlayInterstitialAd("autoShowIntersititial");
}
}
#endregion
}
}