| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  | using System.Collections; | 
					
						
							|  |  |  |  | using System.Collections.Generic; | 
					
						
							|  |  |  |  | using UnityEngine; | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  | using UnityEngine.UI; | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace MMO | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     public static class MMOUtils | 
					
						
							|  |  |  |  |     { | 
					
						
							|  |  |  |  |         public static Sprite LoadTaskIcon(MMOTaskType pType) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             string tPath = ""; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             switch (pType) | 
					
						
							|  |  |  |  |             { | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |                 case MMOTaskType.GetDiamond: tPath = "MMOImage/TaskIcon/Robux"; break; | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |                 case MMOTaskType.PassLevel: | 
					
						
							|  |  |  |  |                 case MMOTaskType.DailyLevel: tPath = "MMOImage/TaskIcon/Level"; break; | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  |                 case MMOTaskType.WatchRV: | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |                 case MMOTaskType.DailyAds: tPath = "MMOImage/TaskIcon/WatchAd"; break; | 
					
						
							|  |  |  |  |                 case MMOTaskType.RiseRank: tPath = "MMOImage/TaskIcon/Rank"; break; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |              | 
					
						
							|  |  |  |  |             return Resources.Load<Sprite>(tPath); | 
					
						
							|  |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2022-09-09 14:35:49 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         public static string GetMaskedID(string pID) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             string tMaskedID = pID; | 
					
						
							|  |  |  |  |             if (tMaskedID.Length >= 2) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tMaskedID = tMaskedID.Replace(tMaskedID.Substring(1, Mathf.Min(3, tMaskedID.Length - 1)), "***"); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return tMaskedID; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         public static T RandomPick<T>(Dictionary<T, float> pDataDic) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (pDataDic == null || pDataDic.Count == 0) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 return default(T); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             Dictionary<T, Vector2> tRandomDic = new Dictionary<T, Vector2>(); | 
					
						
							|  |  |  |  |             float tBottomLine = 0; | 
					
						
							|  |  |  |  |             float tTopLine = 0; | 
					
						
							|  |  |  |  |             foreach (T tKey in pDataDic.Keys) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 tTopLine += pDataDic[tKey]; | 
					
						
							|  |  |  |  |                 tRandomDic.Add(tKey, new Vector2(tBottomLine, tTopLine)); | 
					
						
							|  |  |  |  |                 tBottomLine = tTopLine; | 
					
						
							|  |  |  |  |                 //Debug.Log(string.Format("{0}:{1}", tKey.ToString(), tRandomDic[tKey].ToString())); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             T tPickedEle = default(T); | 
					
						
							|  |  |  |  |             float tRandomNum = Random.Range(0, tTopLine); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             foreach (T tKey in tRandomDic.Keys) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 if (tRandomNum > tRandomDic[tKey].x && tRandomNum <= tRandomDic[tKey].y) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     tPickedEle = tKey; | 
					
						
							|  |  |  |  |                     break; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return tPickedEle; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         #region UI Grey | 
					
						
							|  |  |  |  |         private static Material grayMat; | 
					
						
							|  |  |  |  |         private static Material GetGrayMat() | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (grayMat == null) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 Shader shader = Shader.Find("Custom/UI-Gray"); | 
					
						
							|  |  |  |  |                 if (shader == null) | 
					
						
							|  |  |  |  |                 { | 
					
						
							|  |  |  |  |                     Debug.Log("UI-Gray shader null"); | 
					
						
							|  |  |  |  |                     return null; | 
					
						
							|  |  |  |  |                 } | 
					
						
							|  |  |  |  |                 Material mat = new Material(shader); | 
					
						
							|  |  |  |  |                 grayMat = mat; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |             return grayMat; | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         public static void SetImageGray(Image pImg, bool pGray) | 
					
						
							|  |  |  |  |         { | 
					
						
							|  |  |  |  |             if (pGray) | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 pImg.material = GetGrayMat(); | 
					
						
							|  |  |  |  |                 pImg.SetMaterialDirty(); | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |             else | 
					
						
							|  |  |  |  |             { | 
					
						
							|  |  |  |  |                 pImg.material = null; | 
					
						
							|  |  |  |  |             } | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |         #endregion | 
					
						
							| 
									
										
										
										
											2022-07-04 11:17:39 +00:00
										 |  |  |  |     } | 
					
						
							|  |  |  |  | } |