Пример #1
0
        private void SaveEntity(Tree <Entity> .Branch <Entity> branch, XMLAbstraction.Node parent)
        {
            //Entity Header
            var entityNode = parent.AddNode("Entity");

            entityNode.AddAttribute("active", branch.Value.active.ToString());
            entityNode.AddAttribute("name", branch.Value.name.ToString());
            entityNode.AddAttribute("layer", branch.Value.Layer.ToString());
            entityNode.AddAttribute("id", branch.Value.ID.ToString());

            //Tags
            var tagsNode = entityNode.AddNode("Tags");

            foreach (string t in branch.Value.tags)
            {
                tagsNode.AddNode("Tag", t);
            }

            //Transform
            var transformNode = entityNode.AddNode("Transform");

            //Position
            TypeSerialization.SerializeVector3(branch.Value.transform.position, transformNode.AddNode("Position").node, transformNode.xml);
            //Rotation
            TypeSerialization.SerializeQuaternion(branch.Value.transform.rotation, transformNode.AddNode("Rotation").node, transformNode.xml);
            //Scale
            TypeSerialization.SerializeVector3(branch.Value.transform.scale, transformNode.AddNode("Scale").node, transformNode.xml);

            //Components
            var componentsNode = entityNode.AddNode("Components");

            foreach (Component c in branch.Value.components)
            {
                SaveComponent(c, componentsNode);
            }

            //Child Entities
            var childrenNode = entityNode.AddNode("Children");

            if (branch.BranchCount > 0)
            {
                foreach (var b in branch.Branches)
                {
                    SaveEntity(b, childrenNode);
                }
            }
        }
Пример #2
0
        private void SaveComponent(Component c, XMLAbstraction.Node parentNode)
        {
            var componentNode = parentNode.AddNode("Component");

            componentNode.AddAttribute("enabled", c.enabled.ToString());
            componentNode.AddAttribute("name", c.GetType().FullName);

            //Fields
            var fieldsNode = componentNode.AddNode("Fields");

            foreach (var f in c.GetType().GetFields())
            {
                if (f.Name != "transform" && f.Name != "enabled")
                {
                    var fieldNode = fieldsNode.AddNode("Field");
                    fieldNode.AddAttribute("name", f.Name);
                    fieldNode.AddAttribute("type", f.FieldType.FullName);
                    TypeSerialization.SerializeField(f, c, fieldNode.node, fieldNode.xml);
                }
            }
        }