You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			54 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
		
		
			
		
	
	
			54 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
| 
											2 years ago
										 | using System; | ||
|  | using System.Collections.Generic; | ||
|  | using UnityEngine; | ||
|  | 
 | ||
|  | namespace Game | ||
|  | { | ||
|  |     public static class StringHelper | ||
|  |     { | ||
|  |         static StringHelper() | ||
|  |         { | ||
|  | 
 | ||
|  |         } | ||
|  |         public static object TryParse(string value) | ||
|  |         { | ||
|  |             float valueFloat = 0f; | ||
|  |             int valueInt = 0; | ||
|  |             if (float.TryParse(value, out valueFloat)) | ||
|  |             { | ||
|  |                 return valueFloat; | ||
|  |             } | ||
|  |             if (Int32.TryParse(value, out valueInt)) | ||
|  |             { | ||
|  |                 return valueInt; | ||
|  |             } | ||
|  |             return value; | ||
|  |         } | ||
|  |         /// <summary> | ||
|  |         /// 空格分隔的参数字符串,转化为数字类型的参数列表 | ||
|  |         /// </summary> | ||
|  |         /// <param name="valueStr"></param> | ||
|  |         /// <returns></returns> | ||
|  |         public static List<object> ParseToParam(string valueStr) | ||
|  |         { | ||
|  |             string[] paramStr = valueStr.Replace("\n", "").Split(' '); | ||
|  |             List<object> paramList = new List<object>(); | ||
|  |             foreach (var paramValue in paramStr) | ||
|  |             { | ||
|  |                 if (paramValue != "") | ||
|  |                 { | ||
|  |                     paramList.Add(TryParse(paramValue)); | ||
|  |                 } | ||
|  |             } | ||
|  |             return paramList; | ||
|  |         } | ||
|  |         public static string VectorToStr(Vector2 vec) | ||
|  |         { | ||
|  |             return $"({Math.Round(vec.x, 2)},{Math.Round(vec.y, 2)})"; | ||
|  |         } | ||
|  |         public static string VectorToStr(Vector3 vec) | ||
|  |         { | ||
|  |             return $"({Math.Round(vec.x, 2)},{Math.Round(vec.y, 2)},{Math.Round(vec.z, 2)})"; | ||
|  |         } | ||
|  |     } | ||
|  | } |