95 lines
3.5 KiB
C#
95 lines
3.5 KiB
C#
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
|
||
}
|
||
} |