Represents an animation of a Spriter character.
Пример #1
0
        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);
                    }
                }
            }
        }
Пример #2
0
        void ReadEntity(XmlElement element)
        {
            foreach(XmlAttribute attribute in element.Attributes)
            {
                // id
                if (attribute.Name.Equals("id"))
                    m_Data.entity.ID = int.Parse(attribute.Value);

                // name
                else if (attribute.Name.Equals("name"))
                    m_Data.entity.name = attribute.Value;
            }

            if (m_Data.entity.name.Length == 0)
                m_Data.entity.name = "noname";

            foreach(XmlElement child in element)
            {
                // meta_data
                if (child.Name.Equals("meta_data"))
                    ReadMetaData(child, m_Data.entity.metaData);

                // animation
                else if (child.Name.Equals("animation"))
                {
                    SpriterAnimation animation = new SpriterAnimation();
                    m_Data.entity.animations.Add(animation);

                    foreach(XmlAttribute attribute in child.Attributes)
                    {
                        // id
                        if (attribute.Name.Equals("id"))
                            animation.ID = int.Parse(attribute.Value);

                        // name
                        else if (attribute.Name.Equals("name"))
                            animation.name = attribute.Value;

                        // length
                        else if (attribute.Name.Equals("length"))
                            animation.length = int.Parse(attribute.Value);

                        // looping
                        else if (attribute.Name.Equals("looping"))
                        {
                            animation.playbackTypeRaw = attribute.Value;
                            animation.playbackType = SpriterDataHelpers.ParseSpriterEnum<PlaybackType>(animation.playbackTypeRaw);
                        }

                        // loop_to
                        else if (attribute.Name.Equals("loop_to"))
                            animation.loopTo = int.Parse(attribute.Value);
                    }

                    foreach(XmlElement child2 in child)
                    {
                        // meta_data
                        if (child2.Name.Equals("meta_data"))
                            ReadMetaData(child2, animation.metaData);

                        // mainline
                        else if (child2.Name.Equals("mainline"))
                            ReadMainline(child2, animation);

                        // timeline
                        else if (child2.Name.Equals("timeline"))
                            ReadTimeline(child2, animation);
                    }
                }
            }
        }
Пример #3
0
        void ReadMainline(XmlElement element, SpriterAnimation animation)
        {
            foreach(XmlElement child in element)
            {
                // key
                if (child.Name.Equals("key"))
                {
                    SpriterMainlineKey key = new SpriterMainlineKey();
                    animation.mainline.keys.Add(key);

                    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);
                    }

                    foreach(XmlElement child2 in child)
                    {
                        // meta_data
                        if (child2.Name.Equals("meta_data"))
                            ReadMetaData(child2, key.metaData);

                        // hierarchy
                        else if (child2.Name.Equals("hierarchy"))
                            ReadHierarchy(child2, key.hierarchy);

                        // object
                        else if (child2.Name.Equals("object"))
                            ReadMainlineObject(child2, key);

                        // object_ref
                        else if (child2.Name.Equals("object_ref"))
                            ReadMainlineObjectRef(child2, key);

                        // Spriter doesn't always output files to the spec;
                        // check for bones here too
                        // bone
                        else if (child2.Name.Equals("bone"))
                        {
                            ReadBone(key.hierarchy, child2);
                        }

                        // bone_ref
                        else if (child2.Name.Equals("bone_ref"))
                        {
                            ReadBoneRef(key.hierarchy, child2);
                        }
                    }
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Finds a timeline object for an animation by its ID and time.
        /// </summary>
        ///	<remarks>
        /// Returns null if no object is found or the IDs are invalid.
        /// </remarks>
        /// TODO: Timelines currently only track one object, can probably simplify object model and remove the list
        public SpriterTimelineObject FindTimelineObject(SpriterAnimation animation, int timelineID, int keyID, int time)
        {
            if (animation == null || timelineID < 0 || keyID < 0)
                return null;

            foreach(SpriterTimeline timeline in animation.timelines)
            {
                if (timeline.ID != timelineID)
                    continue;

                foreach(SpriterTimelineKey key in timeline.keys)
                {
                    if (key.ID != keyID)
                        continue;

                    foreach(SpriterTimelineObjectBase obj in key.objects)
                    {
                        if (obj is SpriterTimelineObject)
                            return (SpriterTimelineObject)obj;
                    }
                }
            }
            return null;
        }