void ReadMainlineObject(XmlElement element, SpriterMainlineKey key)
{
SpriterMainlineObject obj = new SpriterMainlineObject();
key.objects.Add(obj);
Vector2 position = Vector2.zero, pivot = new Vector2(0, 1), scale = Vector2.one;
Color color = Color.white;
foreach(XmlAttribute attribute in element.Attributes)
{
// id
if (attribute.Name.Equals("id"))
obj.ID = int.Parse(attribute.Value);
// parent
else if (attribute.Name.Equals("parent"))
obj.parent = int.Parse(attribute.Value);
// object_type
else if (attribute.Name.Equals("object_type"))
{
obj.objectTypeRaw = attribute.Value;
obj.objectType = SpriterDataHelpers.ParseSpriterEnum<ObjectType>(obj.objectTypeRaw);
}
// atlas
else if (attribute.Name.Equals("atlas"))
obj.atlas = int.Parse(attribute.Value);
// folder
else if (attribute.Name.Equals("folder"))
obj.folder = int.Parse(attribute.Value);
// file
else if (attribute.Name.Equals("file"))
obj.file = int.Parse(attribute.Value);
// usage
else if (attribute.Name.Equals("usage"))
{
obj.usageRaw = attribute.Value;
obj.usage = SpriterDataHelpers.ParseSpriterEnum<UsageType>(obj.usageRaw);
}
// blend_mode
else if (attribute.Name.Equals("blend_mode"))
{
obj.blendModeRaw = attribute.Value;
obj.blendMode = SpriterDataHelpers.ParseSpriterEnum<BlendMode>(obj.blendModeRaw);
}
// name
else if (attribute.Name.Equals("name"))
obj.name = attribute.Value;
// x, y
else if (attribute.Name.Equals("x"))
position.x = float.Parse(attribute.Value);
else if (attribute.Name.Equals("y"))
position.y = float.Parse(attribute.Value);
// pivot_x, pivot_y
else if (attribute.Name.Equals("pivot_x"))
pivot.x = float.Parse(attribute.Value);
else if (attribute.Name.Equals("pivot_y"))
pivot.y = float.Parse(attribute.Value);
// angle
else if (attribute.Name.Equals("angle"))
obj.angle = float.Parse(attribute.Value);
// w, h
else if (attribute.Name.Equals("w"))
obj.pixelWidth = int.Parse(attribute.Value);
else if (attribute.Name.Equals("h"))
obj.pixelHeight = int.Parse(attribute.Value);
// scale_x, scale_y
else if (attribute.Name.Equals("scale_x"))
scale.x = float.Parse(attribute.Value);
else if (attribute.Name.Equals("scale_y"))
scale.y = float.Parse(attribute.Value);
// r, g, b, a
else if (attribute.Name.Equals("r"))
color.r = float.Parse(attribute.Value);
else if (attribute.Name.Equals("g"))
color.g = float.Parse(attribute.Value);
else if (attribute.Name.Equals("b"))
color.b = float.Parse(attribute.Value);
else if (attribute.Name.Equals("a"))
color.a = float.Parse(attribute.Value);
// variable_type
else if (attribute.Name.Equals("variable_type"))
{
obj.variableTypeRaw = attribute.Value;
obj.variableType = SpriterDataHelpers.ParseSpriterEnum<VariableType>(obj.variableTypeRaw);
}
// value
else if (attribute.Name.Equals("value"))
obj.value = ReadVariable(obj.variableType, attribute.Value);
// min, max
else if (attribute.Name.Equals("min"))
obj.min = ReadVariable(obj.variableType, attribute.Value);
else if (attribute.Name.Equals("max"))
obj.max = ReadVariable(obj.variableType, attribute.Value);
// animation
else if (attribute.Name.Equals("animation"))
obj.entityAnimation = int.Parse(attribute.Value);
// t
else if (attribute.Name.Equals("t"))
obj.entityT = float.Parse(attribute.Value);
// z_index
else if (attribute.Name.Equals("z_index"))
obj.zIndex = int.Parse(attribute.Value);
// volume
else if (attribute.Name.Equals("volume"))
obj.volume = float.Parse(attribute.Value);
// panning
else if (attribute.Name.Equals("panning"))
obj.panning = float.Parse(attribute.Value);
}
foreach(XmlElement child in element)
{
// meta_data
if (child.Name.Equals("meta_data"))
ReadMetaData(child, obj.metaData);
}
// Assign vector values
obj.position = position;
obj.pivot = pivot;
obj.scale = scale;
obj.color = color;
// Object references
obj.targetAtlas = m_Data.FindAtlas(obj.atlas);
obj.targetFile = m_Data.FindFile(obj.folder, obj.file);
}