public static object ConvertFromStringValue(S_Type sType, string StringValue) { switch (sType) { case S_Type._vector3: return(VectorConvert.StringToVector3(StringValue)); case S_Type._vector2: return(VectorConvert.StringToVector2(StringValue)); case S_Type._bool: return(System.Convert.ToBoolean(StringValue)); case S_Type._float: return(float.Parse(StringValue, System.Globalization.CultureInfo.InvariantCulture.NumberFormat)); case S_Type._int: return(int.Parse(StringValue, System.Globalization.CultureInfo.InvariantCulture.NumberFormat)); case S_Type._color: return(ColorUtility.TryParseHtmlString("#" + StringValue, out Color c) ? c : Color.black); case S_Type._string: return(StringValue); case S_Type._enum: { var s = StringValue.Split(','); var enumType = MacacaGames.Utility.GetType(s[0]); return(System.Enum.Parse(enumType, s[1], false)); } case S_Type._enumFlag: { var s = StringValue.Split(','); var enumType = MacacaGames.Utility.GetType(s[0]); int v = 0; int.TryParse(s[1], out v); return(System.Enum.ToObject(enumType, v)); } default: return(null); } }
public static string ConvertToStringValue(object value) { if (value == null) { return(""); } else if (value is Vector3) { return(VectorConvert.Vector3ToString((Vector3)value)); } else if (value is Vector2) { return(VectorConvert.Vector2ToString((Vector2)value)); } else if (value is Color) { return(ColorUtility.ToHtmlStringRGBA((Color)value)); } else if (value.GetType().IsEnum) { bool isFlag = false; isFlag = value.GetType().GetCustomAttribute(typeof(System.FlagsAttribute)) != null; if (isFlag) { return(value.GetType().ToString() + "," + (int)value); } else { return(value.GetType().ToString() + "," + value.ToString()); } } else { return(value.ToString()); } }