88 lines
		
	
	
		
			3.2 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			88 lines
		
	
	
		
			3.2 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; | |||
|  | 
 | |||
|  |         public void Init() | |||
|  |         { | |||
|  | 
 | |||
|  |         } | |||
|  | 
 | |||
|  |         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) | |||
|  |             { | |||
|  |                 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 eventName = string.Format("AUTO_{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(eventName); | |||
|  |                 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 | |||
|  |     } | |||
|  | } |