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; } /// /// 空格分隔的参数字符串,转化为数字类型的参数列表 /// /// /// public static List ParseToParam(string valueStr) { string[] paramStr = valueStr.Replace("\n", "").Split(' '); List paramList = new List(); 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)})"; } } }