| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | using System; | 
					
						
							|  |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							|  |  |  |  | using Touka; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public class TKGUtils | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 是否首次触达某个事件 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static bool IfFirstCheckPlayerPrefs(string _key) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         var isFirstClick = GetPlayerPrefsIntByKey(_key) == 0; | 
					
						
							|  |  |  |  |         SavePlayerPrefsIntByKeyValue(_key, 1); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         return isFirstClick; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 本地存int | 
					
						
							|  |  |  |  |     /// | 
					
						
							|  |  |  |  |     /// key 内部拼接了前缀:Touka_ | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <param name="_defaultValue"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static int GetPlayerPrefsIntByKey(string _key, int _defaultValue = 0) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         int value = PlayerPrefs.GetInt(string.Format("{0}{1}", StaticStringsPlayerPrefs.TOUKA_PREFIX, _key), _defaultValue); | 
					
						
							|  |  |  |  |         return value; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 本地取int | 
					
						
							|  |  |  |  |     /// | 
					
						
							|  |  |  |  |     /// key 内部拼接了前缀:Touka_ | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <param name="_newValue"></param> | 
					
						
							|  |  |  |  |     public static void SavePlayerPrefsIntByKeyValue(string _key, int _newValue) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         PlayerPrefs.SetInt(string.Format("{0}{1}", StaticStringsPlayerPrefs.TOUKA_PREFIX, _key), _newValue); | 
					
						
							|  |  |  |  |         PlayerPrefs.Save(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 本地存string | 
					
						
							|  |  |  |  |     /// | 
					
						
							|  |  |  |  |     /// key 内部拼接了前缀:Touka_ | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <param name="_defaultValue"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static string GetPlayerPrefsStringByKey(string _key, string _defaultValue = "") | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         string value = PlayerPrefs.GetString(string.Format("{0}{1}", StaticStringsPlayerPrefs.TOUKA_PREFIX, _key), _defaultValue); | 
					
						
							|  |  |  |  |         return value; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 本地取string | 
					
						
							|  |  |  |  |     /// | 
					
						
							|  |  |  |  |     /// key 内部拼接了前缀:Touka_ | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <param name="_newValue"></param> | 
					
						
							|  |  |  |  |     public static void SavePlayerPrefsStringByKeyValue(string _key, string _newValue) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         PlayerPrefs.SetString(string.Format("{0}{1}", StaticStringsPlayerPrefs.TOUKA_PREFIX, _key), _newValue); | 
					
						
							|  |  |  |  |         PlayerPrefs.Save(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 缓存当前时间 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     public static void SaveCurrTime2PlayerPrefs(string _key) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         DateTime date1 = DateTime.Now; | 
					
						
							|  |  |  |  |         string s1 = date1.ToString(); | 
					
						
							|  |  |  |  |         SavePlayerPrefsStringByKeyValue(_key, s1); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 缓存本地时间为string | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <param name="_dateStr"></param> | 
					
						
							|  |  |  |  |     public static void SaveCurrTime2PlayerPrefsWithStringDate(string _key, string _dateStr) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         SavePlayerPrefsStringByKeyValue(_key, _dateStr); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 取出缓存string时间为 DateTime | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="_key"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static DateTime GetDateTimeFromPlayerPrefs(string _key) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         string firstDateValue = GetPlayerPrefsStringByKey(_key); | 
					
						
							|  |  |  |  |         if (string.IsNullOrEmpty(firstDateValue)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return new DateTime(1990, 1, 1, 0, 0, 0); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         DateTime dateOld = Convert.ToDateTime(firstDateValue); | 
					
						
							|  |  |  |  |         return dateOld; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// 判断是否为新用户 | 
					
						
							|  |  |  |  |     /// | 
					
						
							|  |  |  |  |     /// 距离首次登录时间间隔24h以内为新用户 | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static bool isNewUser() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         DateTime dateCurr = DateTime.Now; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         string firstDateValue = GetPlayerPrefsStringByKey(StaticStringsPlayerPrefs.FirstLoginTime); | 
					
						
							|  |  |  |  |         if (string.IsNullOrEmpty(firstDateValue)) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Debug.Log("存的值为空,为新用户"); | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         Debug.Log("读取出来的值: " + firstDateValue + " , 现在的时间值:" + dateCurr.ToString());     // 06/16/2019 19:46:57 | 
					
						
							|  |  |  |  |         DateTime dateOld = Convert.ToDateTime(firstDateValue); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         TimeSpan timeSpan = dateCurr - dateOld; | 
					
						
							|  |  |  |  |         Debug.Log("timeSpan.Seconds : " + timeSpan.TotalMinutes); | 
					
						
							|  |  |  |  |         if (timeSpan.TotalMinutes >= 24 * 60) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             Debug.Log("不是新用户了"); | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         Debug.Log("是新用户"); | 
					
						
							|  |  |  |  |         return true; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// equal double | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <param name="a"></param> | 
					
						
							|  |  |  |  |     /// <param name="b"></param> | 
					
						
							|  |  |  |  |     /// <returns></returns> | 
					
						
							|  |  |  |  |     public static bool equalDouble(double a, double b) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if ((a - b > -0.000001) && (a - b) < 0.000001) | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /// <summary> | 
					
						
							|  |  |  |  |     /// Floats the equal. | 
					
						
							|  |  |  |  |     /// </summary> | 
					
						
							|  |  |  |  |     /// <returns><c>true</c>, if equal was floated, <c>false</c> otherwise.</returns> | 
					
						
							|  |  |  |  |     /// <param name="a">The alpha component.</param> | 
					
						
							|  |  |  |  |     /// <param name="b">The blue component.</param> | 
					
						
							|  |  |  |  |     public static bool FloatEqual(float a, float b) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         if ((a - b > -0.000001) && (a - b) < 0.000001) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return true; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         else | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             return false; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static string GetTodayDataStr() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         string timeStr = DateTime.Now.ToString("yyyy-MM-dd"); | 
					
						
							|  |  |  |  |         return timeStr; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static void OpenBrowserUrl(string _url) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         Application.OpenURL(_url); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     #region unity sdk only | 
					
						
							|  |  |  |  |     public static void InitTenjinFirst() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         ToukaUtils.InitTenjinFirst(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static void ActiveAutoIV(bool pActive) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         AutoIntersititialManager.Instance.ActiveLogic(pActive); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |     public static bool WillPlayInterstitial(bool pNormalIV = true) | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-06-08 13:23:44 +00:00
										 |  |  |  |         return ToukaInterstitialTimer.Instance.CanShow(pNormalIV ? ToukaSDKManager.IVType.IV1 : ToukaSDKManager.IVType.IV2, true) && ToukaAdManager.Instance.IsReadyIntersitial(); | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static bool IsNativeReady() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         return ToukaAdManager.Instance.IsReadyNative; | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static void ShowNative(Vector3 pTL, Vector3 pBR, string pAdPos, Camera pCam = null) | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         Vector2 tTopLeft = RectTransformUtility.WorldToScreenPoint(pCam, pTL); | 
					
						
							|  |  |  |  |         Vector2 tBottomRight = RectTransformUtility.WorldToScreenPoint(pCam, pBR); | 
					
						
							|  |  |  |  |         float tWidth = Mathf.Abs(tBottomRight.x - tTopLeft.x); | 
					
						
							|  |  |  |  |         float tHeight = Mathf.Abs(tBottomRight.y - tTopLeft.y); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         Debug.Log("TKG Native top left :" + tTopLeft); | 
					
						
							|  |  |  |  |         Debug.Log("TKG Native bottom right :" + tBottomRight); | 
					
						
							|  |  |  |  |         //Debug.Log("TKG Native width :" + Mathf.Abs(pBottomRight.x - pTopLeft.x)); | 
					
						
							|  |  |  |  |         //Debug.Log("TKG Native height :" + Mathf.Abs(pBottomRight.y - pTopLeft.y)); | 
					
						
							|  |  |  |  |         //Debug.Log("TKG Native screen width :" + Screen.width); | 
					
						
							|  |  |  |  |         //Debug.Log("TKG Native screen height :" + Screen.height); | 
					
						
							|  |  |  |  |         if (ToukaAdManager.Instance.IsReadyNative) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             ToukaAdManager.Instance.ShowNative(tTopLeft.x, Screen.height - tTopLeft.y, tWidth, tHeight, pAdPos); | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     public static void RemoveNative() | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         ToukaAdManager.Instance.HideNative(false); | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-06-13 07:55:30 +00:00
										 |  |  |  |     #endregion | 
					
						
							| 
									
										
										
										
											2022-05-23 13:39:59 +00:00
										 |  |  |  | } |