예제 #1
0
        public static void AddUnityEngineConverters()
        {
            var colorConverter = new TypeConverter
            {
                ConvertToString = (obj, type) => ColorUtility.ToHtmlStringRGBA((Color)obj),
                ConvertToObject = (str, type) =>
                {
                    if (!ColorUtility.TryParseHtmlString("#" + str.Trim('#', ' '), out var c))
                    {
                        throw new FormatException("Invalid color string, expected hex #RRGGBBAA");
                    }
                    return(c);
                },
            };

            TomlTypeConverter.AddConverter(typeof(Color), colorConverter);

            var jsonConverter = new TypeConverter
            {
                ConvertToString = (obj, type) => JsonUtility.ToJson(obj),
                ConvertToObject = (str, type) => JsonUtility.FromJson(type: type, json: str),
            };

            TomlTypeConverter.AddConverter(typeof(Vector2), jsonConverter);
            TomlTypeConverter.AddConverter(typeof(Vector3), jsonConverter);
            TomlTypeConverter.AddConverter(typeof(Vector4), jsonConverter);
            TomlTypeConverter.AddConverter(typeof(Quaternion), jsonConverter);
        }
예제 #2
0
 static KeyboardShortcut()
 {
     TomlTypeConverter.AddConverter(
         typeof(KeyboardShortcut),
         new TypeConverter
     {
         ConvertToString = (o, type) => ((KeyboardShortcut)o).Serialize(),
         ConvertToObject = (s, type) => Deserialize(s)
     });
 }