void ReadTimelineObject(XmlElement element, SpriterTimelineKey key, VariableType variableType) { SpriterTimelineObject obj = new SpriterTimelineObject(); 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) { // atlas 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); // 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); // color 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); // blend_mode else if (attribute.Name.Equals("blend_mode")) { obj.blendModeRaw = attribute.Value; obj.blendMode = SpriterDataHelpers.ParseSpriterEnum<BlendMode>(obj.blendModeRaw); } // value else if (attribute.Name.Equals("value")) obj.value = ReadVariable(variableType, attribute.Value); // min, max else if (attribute.Name.Equals("min")) obj.min = ReadVariable(variableType, attribute.Value); else if (attribute.Name.Equals("max")) obj.max = ReadVariable(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); // 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); }
void ReadTimeline(XmlElement element, SpriterAnimation animation) { SpriterTimeline timeline = new SpriterTimeline(); animation.timelines.Add(timeline); foreach(XmlAttribute attribute in element.Attributes) { // id if (attribute.Name.Equals("id")) timeline.ID = int.Parse(attribute.Value); // name else if (attribute.Name.Equals("name")) timeline.name = attribute.Value; // object_type else if (attribute.Name.Equals("object_type")) { timeline.objectTypeRaw = attribute.Value; timeline.objectType = SpriterDataHelpers.ParseSpriterEnum<ObjectType>(timeline.objectTypeRaw); } // variable_type else if (attribute.Name.Equals("variable_type")) { timeline.variableTypeRaw = attribute.Value; timeline.variableType = SpriterDataHelpers.ParseSpriterEnum<VariableType>(timeline.variableTypeRaw); } // usage else if (attribute.Name.Equals("usage")) { timeline.usageRaw = attribute.Value; timeline.usage = SpriterDataHelpers.ParseSpriterEnum<UsageType>(timeline.usageRaw); } } foreach(XmlElement child in element) { // meta_data if (child.Name.Equals("meta_data")) ReadMetaData(child, timeline.metaData); // key else if (child.Name.Equals("key")) { SpriterTimelineKey key = new SpriterTimelineKey(); timeline.keys.Add(key); Vector2 tangents = Vector2.zero; foreach(XmlAttribute attribute in child.Attributes) { // id if (attribute.Name.Equals("id")) key.ID = int.Parse(attribute.Value); // time else if (attribute.Name.Equals("time")) key.time = int.Parse(attribute.Value); // curve_type else if (attribute.Name.Equals("curve_type")) { key.curveTypeRaw = attribute.Value; key.curveType = SpriterDataHelpers.ParseSpriterEnum<CurveType>(key.curveTypeRaw); } // c1, c2 else if (attribute.Name.Equals("c1")) tangents.x = float.Parse(attribute.Value); else if (attribute.Name.Equals("c2")) tangents.y = float.Parse(attribute.Value); // spin else if (attribute.Name.Equals("spin")) key.spin = int.Parse(attribute.Value); } // Assign vector values key.curveTangents = tangents; foreach(XmlElement child2 in child) { // meta_data if (child2.Name.Equals("meta_data")) ReadMetaData(child2, key.metaData); // bone else if (child2.Name.Equals("bone")) ReadTimelineBone(child2, key); // object else if (child2.Name.Equals("object")) ReadTimelineObject(child2, key, timeline.variableType); } } } }
void ReadTimelineBone(XmlElement element, SpriterTimelineKey key) { SpriterTimelineBone bone = new SpriterTimelineBone(); key.objects.Add(bone); Vector2 position = Vector2.zero, scale = Vector2.one; Color color = Color.white; foreach(XmlAttribute attribute in element.Attributes) { // x, y if (attribute.Name.Equals("x")) position.x = float.Parse(attribute.Value); else if (attribute.Name.Equals("y")) position.y = float.Parse(attribute.Value); // angle else if (attribute.Name.Equals("angle")) bone.angle = float.Parse(attribute.Value); // scale 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); // color 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); } foreach(XmlElement child in element) { // meta_data if (child.Name.Equals("meta_data")) ReadMetaData(child, bone.metaData); } // Assign vector values bone.position = position; bone.scale = scale; bone.color = color; }