Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public sealed class ColorConverter : IYamlTypeConverter
public bool Accepts(Type type)
{
Type baseType = Nullable.GetUnderlyingType(type) ?? type;
return baseType == typeof(Color);
return baseType == typeof(Color) || baseType == typeof(Color32);
}

/// <inheritdoc cref="IYamlTypeConverter" />
Expand All @@ -57,6 +57,8 @@ public object ReadYaml(IParser parser, Type type)
List<object> coordinates = ListPool<object>.Pool.Get(4);
int i = 0;

bool isColor32 = baseType == typeof(Color32);

while (!parser.TryConsume<MappingEnd>(out _))
{
if (i++ % 2 == 0)
Expand All @@ -71,6 +73,11 @@ public object ReadYaml(IParser parser, Type type)
throw new InvalidDataException("Invalid float value.");
}

if (isColor32)
{
coordinates.Add((byte)Mathf.Round(Mathf.Clamp01(coordinate) * 255f));
}

coordinates.Add(coordinate);
}

Expand Down Expand Up @@ -99,6 +106,14 @@ public void WriteYaml(IEmitter emitter, object value, Type type)
coordinates["b"] = color.b;
coordinates["a"] = color.a;
}
else if (value is Color32 color32)
{
color = color32;
coordinates["r"] = color.r;
coordinates["g"] = color.g;
coordinates["b"] = color.b;
coordinates["a"] = color.a;
}

emitter.Emit(new MappingStart());

Expand Down
Loading