| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | using System.Collections; | 
					
						
							|  |  |  | using System.Collections.Generic; | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  | using System.Globalization; | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  | using UnityEngine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace WZ | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |     public static class DataUtils | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         [System.Serializable] | 
					
						
							|  |  |  |         private class Wrapper<T> | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             public T[] items; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-18 10:30:57 +00:00
										 |  |  |         public static int AndroidVersionCode() | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             AndroidJavaClass contextCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); | 
					
						
							|  |  |  |             AndroidJavaObject context = contextCls.GetStatic<AndroidJavaObject>("currentActivity"); | 
					
						
							|  |  |  |             AndroidJavaObject packageMngr = context.Call<AndroidJavaObject>("getPackageManager"); | 
					
						
							|  |  |  |             string packageName = context.Call<string>("getPackageName"); | 
					
						
							|  |  |  |             AndroidJavaObject packageInfo = | 
					
						
							|  |  |  |                 packageMngr.Call<AndroidJavaObject>("getPackageInfo", packageName, 0); | 
					
						
							|  |  |  |             return packageInfo.Get<int>("versionCode"); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |         public static T[] FromJsonArray<T>(string json) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             string wrappedJson = $"{{\"items\":{json}}}"; | 
					
						
							|  |  |  |             Wrapper<T> wrapper = JsonUtility.FromJson<Wrapper<T>>(wrappedJson); | 
					
						
							|  |  |  |             return wrapper.items; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-18 10:30:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-09-02 05:38:42 +00:00
										 |  |  |         public static double StringToDouble(string str) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             double result = 0; | 
					
						
							|  |  |  |             if (double.TryParse(str, NumberStyles.Any, CultureInfo.InvariantCulture, out result)) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Debug.Log("转换成功: " + result); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 Debug.Log("转换失败:字符串格式不正确"); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             return result; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-18 10:30:57 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         public static void AddIfNotExists<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if (!dictionary.ContainsKey(key)) | 
					
						
							|  |  |  |                 dictionary.Add(key, value); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-09-01 10:32:50 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |