示例#1
0
    GameObject readXmlNode(XmlNode xmlNode, GameObject parent, string fileName)
    {
        GameObject go = new GameObject(xmlNode.Name);

        if (parent != null)
        {
            go.transform.parent = parent.transform;
        }

        if (xmlNode.NodeType == XmlNodeType.Comment)
        {
            CommentElement comment = go.AddComponent <CommentElement>();
            go.transform.parent = parent.transform;

            comment.comment = xmlNode.InnerText;
        }
        else if (xmlNode.Name == "vehicle")
        {
            Vehicle tag = go.AddComponent <Vehicle>();
            go.transform.parent = parent.transform;

            attachGameObjectProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.sound        = readString(xmlNode, "sound");
            tag.spring       = readFloat(xmlNode, "spring");
            tag.acceleration = readFloat(xmlNode, "acceleration");
            tag.antiroll     = readFloat(xmlNode, "antiroll");
            tag.damping      = readFloat(xmlNode, "damping");
            tag.friction     = readFloat(xmlNode, "friction");
            tag.difflock     = readFloat(xmlNode, "difflock");
            tag.steerassist  = readFloat(xmlNode, "steerassist");
            tag.topspeed     = readFloat(xmlNode, "topspeed");
            tag.driven       = readBool(xmlNode, "driven", false);
            tag.antispin     = readFloat(xmlNode, "antispin");
            tag.soundVolume  = readFloat(xmlNode, "soundvolume");

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "wheel")
        {
            Wheel tag = go.AddComponent <Wheel>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.steer  = readFloat(xmlNode, "steer");
            tag.drive  = readFloat(xmlNode, "drive");
            tag.travel = readVec2(xmlNode, "travel");
            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "spawnpoint")
        {
            SpawnPoint tag = go.AddComponent <SpawnPoint>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "location")
        {
            Location tag = go.AddComponent <Location>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "group")
        {
            Group tag = go.AddComponent <Group>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "rope")
        {
            Rope tag = go.AddComponent <Rope>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;

            tag.strength = readFloat(xmlNode, "strength");
            tag.slack    = readFloat(xmlNode, "slack");

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "screen")
        {
            Screen tag = go.AddComponent <Screen>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;

            tag.size        = readVec2(xmlNode, "size");
            tag.isEnabled   = readBool(xmlNode, "enabled", false);
            tag.interactive = readBool(xmlNode, "interactive", false);
            tag.emissive    = readFloat(xmlNode, "emissive");
            tag.color       = readColor(xmlNode, "color");
            tag.resolution  = readVec2(xmlNode, "resolution");
            tag.bulge       = readVec2(xmlNode, "bulge");
            tag.script      = readString(xmlNode, "script");
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "vox")
        {
            Vox tag = go.AddComponent <Vox>();
            go.transform.parent = parent.transform;

            attachGameObjectProperties(tag, xmlNode);
            tag.file      = readString(xmlNode, "file").Replace("LEVEL", getLevelFolder(fileName));;
            tag.voxObject = readString(xmlNode, "object");
            tag.dynamic   = readBool(xmlNode, "prop", false);

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;

            tag.Reload();

            if (tag.scale > 0)
            {
                go.transform.localScale *= tag.scale;
            }

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "joint")
        {
            TeardownJoint tag = go.AddComponent <TeardownJoint>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.type        = (TeardownJoint.Type)Enum.Parse(typeof(TeardownJoint.Type), readString(xmlNode, "type", "ball"), false);
            tag.size        = readFloat(xmlNode, "size");
            tag.rotspring   = readFloat(xmlNode, "rotspring");
            tag.rotstrength = readFloat(xmlNode, "rotstrength");
            tag.limits      = readVec2(xmlNode, "limits");

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "voxbox")
        {
            VoxBox tag = go.AddComponent <VoxBox>();
            go.transform.parent = parent.transform;

            attachGameObjectProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.color   = readColor(xmlNode, "color");
            tag.dynamic = readBool(xmlNode, "prop", false);
            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;

            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.parent        = go.transform;
            cube.transform.localPosition = new Vector3(0.5f, 0.5f, -0.5f);
            cube.transform.localRotation = Quaternion.identity;
            cube.GetComponent <MeshRenderer>().sharedMaterial = new Material(Shader.Find("Standard"));
            go.transform.localScale = tag.size / 10;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "body")
        {
            Body tag = go.AddComponent <Body>();
            go.transform.parent = parent.transform;

            attachGameObjectProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.dynamic = readBool(xmlNode, "dynamic", false);
            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "water")
        {
            go.name = "<" + xmlNode.Name + ">";
            Water tag = go.AddComponent <Water>();
            go.transform.parent = parent.transform;

            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "environment")
        {
            TeardownEnvironment tag = go.AddComponent <TeardownEnvironment>();
            go.transform.parent = parent.transform;

            attachGeneralProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.skyboxrot     = readFloat(xmlNode, "skyboxrot");
            tag.sunBrightness = readFloat(xmlNode, "sunBrightness");
            tag.sunFogScale   = readFloat(xmlNode, "sunFogScale");
            tag.sunDir        = readVec3(xmlNode, "sunDir");
            tag.sunColorTint  = readColor(xmlNode, "sunColorTint");

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "scene")
        {
            Scene tag = go.AddComponent <Scene>();

            go.transform.parent = parent.transform;
            attachGeneralProperties(tag, xmlNode);

            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.shadowVolume = readVec3(xmlNode, "shadowVolume");
            tag.version      = readInt(xmlNode, "version");

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "boundary")
        {
            Boundary tag = go.AddComponent <Boundary>();
            attachGeneralProperties(tag, xmlNode);
            go.transform.parent = parent.transform;
            go.name             = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "script")
        {
            Script tag = go.AddComponent <Script>();
            attachGeneralProperties(tag, xmlNode);
            go.transform.parent = parent.transform;

            tag.file = readString(xmlNode, "file");
            go.name  = "<" + xmlNode.Name + " " + tag.teardownName + " " + tag.file + ">";

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "instance")
        {
            Instance tag = go.AddComponent <Instance>();
            go.transform.parent = parent.transform;
            attachGeneralProperties(tag, xmlNode);

            tag.file = readString(xmlNode, "file");
            go.name  = "<" + xmlNode.Name + " " + tag.teardownName + " " + tag.file + ">";

            if (!fileName.Contains("create") && tag.file.StartsWith("LEVEL"))
            {
                Debug.LogError("Your source file has no create folder in its path but an instance is referencing the level folder. Cannot import!");
            }
            else if (!tag.file.StartsWith("LEVEL"))
            {
                GameObject xmlRoot = readXML(tag.file);
                xmlRoot.GetComponentInChildren <Prefab>().gameObject.transform.transform.parent = go.transform;
                DestroyImmediate(xmlRoot);
            }
            else
            {
                GameObject xmlRoot = readXML(tag.file.Replace("LEVEL", getLevelFolder(fileName)));
                xmlRoot.GetComponentInChildren <Prefab>().gameObject.transform.transform.parent = go.transform;
                DestroyImmediate(xmlRoot);
            }
            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "prefab")
        {
            Prefab tag = go.AddComponent <Prefab>();
            go.transform.parent = parent.transform;

            attachGameObjectProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "vertex")
        {
            Vertex tag = go.AddComponent <Vertex>();
            go.transform.parent = parent.transform;
            attachGeneralProperties(tag, xmlNode);
            tag.pos = readVec2(xmlNode, "pos");

            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";
            go.transform.localPosition = new Vector3(tag.pos.x, 0, tag.pos.y);

            addToParent(parent, tag);
        }
        else if (xmlNode.Name == "light")
        {
            Light tag = go.AddComponent <Light>();
            go.transform.parent = parent.transform;

            attachGeneralProperties(tag, xmlNode);
            attachTransformProperties(tag, xmlNode);
            go.name = "<" + xmlNode.Name + " " + tag.teardownName + ">";

            tag.penumbra   = readFloat(xmlNode, "penumbra");
            tag.unshadowed = readFloat(xmlNode, "unshadowed");
            tag.angle      = readFloat(xmlNode, "angle");
            tag.glare      = readFloat(xmlNode, "glare");
            tag.color      = readColor(xmlNode, "color");
            tag.type       = (Light.Type)Enum.Parse(typeof(Light.Type), readString(xmlNode, "type", "area"), false);

            go.transform.localRotation = Quaternion.Euler(tag.rotation);
            go.transform.localPosition = tag.position;
            if (tag.scale > 0)
            {
                go.transform.localScale = go.transform.localScale * tag.scale;
            }
            addToParent(parent, tag);
        }

        foreach (XmlNode child in xmlNode.ChildNodes)
        {
            GameObject childGameObject = readXmlNode(child, go, fileName);
        }

        return(go);
    }
示例#2
0
    private void exportToXML(XmlDocument xmlDoc, Transform currentObject, XmlNode parent)
    {
        XmlNode node = null;

        if (currentObject.GetComponent <CommentElement>() != null)
        {
            CommentElement commentElement = (CommentElement)currentObject.GetComponent <CommentElement>();

            node = xmlDoc.CreateComment(commentElement.comment);
        }
        else if (currentObject.GetComponent <Scene>() != null)
        {
            Scene tag = (Scene)currentObject.GetComponent <Scene>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "scene", "");

            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);

            XmlAttribute version = xmlDoc.CreateAttribute("version");
            version.Value = tag.version.ToString().Replace(",", ".");;
            node.Attributes.Append(version);

            XmlAttribute shadowvolume = xmlDoc.CreateAttribute("shadowVolume");
            shadowvolume.Value = $"{tag.shadowVolume.x} {tag.shadowVolume.y} {tag.shadowVolume.z}".Replace(",", ".");;
            node.Attributes.Append(shadowvolume);
        }
        else if (currentObject.GetComponent <TeardownEnvironment>() != null)
        {
            TeardownEnvironment tag = (TeardownEnvironment)currentObject.GetComponent <TeardownEnvironment>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "environment", "");
            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("template");
            attribute.Value = tag.template.ToString().ToLower();
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("skyboxrot");
            attribute.Value = tag.skyboxrot.ToString().Replace(",", ".");;
            node.Attributes.Append(attribute);

            if (tag.sunDir != null && !$"{tag.sunDir.x} {tag.sunDir.y} {tag.sunDir.z}".Equals("0 0 0"))
            {
                attribute       = xmlDoc.CreateAttribute("sunDir");
                attribute.Value = $"{tag.sunDir.x} {tag.sunDir.y} {tag.sunDir.z}".Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.sunBrightness >= 0)
            {
                attribute       = xmlDoc.CreateAttribute("sunBrightness");
                attribute.Value = tag.sunBrightness.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.sunFogScale >= 0)
            {
                attribute       = xmlDoc.CreateAttribute("sunFogScale");
                attribute.Value = tag.sunFogScale.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("sunColorTint");
            attribute.Value = $"{tag.sunColorTint.r} {tag.sunColorTint.g} {tag.sunColorTint.b}".Replace(",", ".");
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Body>() != null)
        {
            Body tag = (Body)currentObject.GetComponent <Body>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "body", "");
            enrichXmlWithGameObjectAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("dynamic");
            attribute.Value = tag.dynamic ? "true" : "false";
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Boundary>() != null)
        {
            Boundary tag = (Boundary)currentObject.GetComponent <Boundary>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "boundary", "");
            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);
        }
        else if (currentObject.GetComponent <Vertex>() != null)
        {
            Vertex tag = (Vertex)currentObject.GetComponent <Vertex>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "vertex", "");
            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("pos");
            attribute.Value = $"{tag.pos.x} {tag.pos.y}".Replace(",", ".");;
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Script>() != null)
        {
            Script tag = (Script)currentObject.GetComponent <Script>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "script", "");
            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("file");
            attribute.Value = tag.file.Replace(XmlImporter.getLevelFolder(tag.file), "LEVEL");
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Instance>() != null)
        {
            Instance tag = (Instance)currentObject.GetComponent <Instance>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "instance", "");
            enrichXmlWithGeneralAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("file");
            attribute.Value = tag.file.Replace(XmlImporter.getLevelFolder(tag.file), "LEVEL");
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <SpawnPoint>() != null)
        {
            SpawnPoint tag = (SpawnPoint)currentObject.GetComponent <SpawnPoint>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "spawnpoint", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);
        }
        else if (currentObject.GetComponent <Location>() != null)
        {
            Location tag = (Location)currentObject.GetComponent <Location>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "location", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);
        }
        else if (currentObject.GetComponent <Group>() != null)
        {
            Group tag = (Group)currentObject.GetComponent <Group>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "group", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);
        }
        else if (currentObject.GetComponent <Water>() != null)
        {
            Water tag = (Water)currentObject.GetComponent <Water>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "water", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("size");
            attribute.Value = $"{tag.size.x} {tag.size.y}".Replace(",", ".");
            node.Attributes.Append(attribute);

            if (tag.wave > -1)
            {
                attribute       = xmlDoc.CreateAttribute("wave");
                attribute.Value = tag.wave.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.ripple > -1)
            {
                attribute       = xmlDoc.CreateAttribute("ripple");
                attribute.Value = tag.ripple.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.foam > -1)
            {
                attribute       = xmlDoc.CreateAttribute("foam");
                attribute.Value = tag.foam.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.motion > -1)
            {
                attribute       = xmlDoc.CreateAttribute("motion");
                attribute.Value = tag.motion.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (!String.IsNullOrEmpty(tag.type))
            {
                attribute       = xmlDoc.CreateAttribute("type");
                attribute.Value = tag.type.ToString().ToLower();
                node.Attributes.Append(attribute);
            }
        }
        else if (currentObject.GetComponent <Screen>() != null)
        {
            Screen tag = (Screen)currentObject.GetComponent <Screen>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "water", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("size");
            attribute.Value = $"{tag.size.x} {tag.size.y}".Replace(",", ".");
            node.Attributes.Append(attribute);

            if (!tag.resolution.Equals(Vector2.zero))
            {
                attribute       = xmlDoc.CreateAttribute("resolution");
                attribute.Value = $"{tag.resolution.x} {tag.resolution.y}".Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (!tag.bulge.Equals(Vector2.zero))
            {
                attribute       = xmlDoc.CreateAttribute("bulge");
                attribute.Value = $"{tag.bulge.x} {tag.bulge.y}".Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (!String.IsNullOrEmpty(tag.script))
            {
                attribute       = xmlDoc.CreateAttribute("script");
                attribute.Value = tag.script;
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("color");
            attribute.Value = $"{tag.color.r} {tag.color.g} {tag.color.b}".Replace(",", ".");
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("enabled");
            attribute.Value = tag.enabled ? "true" : "false";
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("interactive");
            attribute.Value = tag.interactive ? "true" : "false";
            node.Attributes.Append(attribute);

            if (tag.emissive > -1)
            {
                attribute       = xmlDoc.CreateAttribute("resolution");
                attribute.Value = tag.emissive.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }
        }
        else if (currentObject.GetComponent <Light>() != null)
        {
            Light tag = (Light)currentObject.GetComponent <Light>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "light", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("type");
            attribute.Value = tag.type.ToString().ToLower();
            node.Attributes.Append(attribute);

            if (tag.glare > -1)
            {
                attribute       = xmlDoc.CreateAttribute("glare");
                attribute.Value = tag.glare.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("angle");
            attribute.Value = tag.angle.ToString().Replace(",", ".");
            node.Attributes.Append(attribute);

            if (tag.penumbra > -1)
            {
                attribute       = xmlDoc.CreateAttribute("penumbra");
                attribute.Value = tag.penumbra.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.unshadowed > -1)
            {
                attribute       = xmlDoc.CreateAttribute("unshadowed");
                attribute.Value = tag.unshadowed.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("color");
            attribute.Value = $"{tag.color.r} {tag.color.g} {tag.color.b}".Replace(",", ".");
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Rope>() != null)
        {
            Rope tag = (Rope)currentObject.GetComponent <Rope>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "rope", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            if (tag.slack > -1)
            {
                XmlAttribute attribute = xmlDoc.CreateAttribute("friction");
                attribute.Value = tag.slack.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.strength > -1)
            {
                XmlAttribute attribute = xmlDoc.CreateAttribute("steerassist");
                attribute.Value = tag.strength.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }
        }
        else if (currentObject.GetComponent <Wheel>() != null)
        {
            Wheel tag = (Wheel)currentObject.GetComponent <Wheel>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "wheel", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("drive");
            attribute.Value = tag.drive.ToString().Replace(",", ".");
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("steer");
            attribute.Value = tag.steer.ToString().Replace(",", ".");
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("travel");
            attribute.Value = $"{tag.travel.x} {tag.travel.y}".Replace(",", ".");
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Vehicle>() != null)
        {
            Vehicle tag = (Vehicle)currentObject.GetComponent <Vehicle>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "vehicle", "");
            enrichXmlWithGameObjectAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("driven");
            attribute.Value = tag.driven ? "true" : "false";
            node.Attributes.Append(attribute);

            if (tag.friction > -1)
            {
                attribute       = xmlDoc.CreateAttribute("friction");
                attribute.Value = tag.friction.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.steerassist > -1)
            {
                attribute       = xmlDoc.CreateAttribute("steerassist");
                attribute.Value = tag.steerassist.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.difflock > -1)
            {
                attribute       = xmlDoc.CreateAttribute("difflock");
                attribute.Value = tag.difflock.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.antiroll > -1)
            {
                attribute       = xmlDoc.CreateAttribute("antiroll");
                attribute.Value = tag.antiroll.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.antispin > -1)
            {
                attribute       = xmlDoc.CreateAttribute("antispin");
                attribute.Value = tag.antispin.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }


            if (tag.acceleration > -1)
            {
                attribute       = xmlDoc.CreateAttribute("acceleration");
                attribute.Value = tag.acceleration.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.spring > -1)
            {
                attribute       = xmlDoc.CreateAttribute("spring");
                attribute.Value = tag.spring.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.damping > -1)
            {
                attribute       = xmlDoc.CreateAttribute("damping");
                attribute.Value = tag.damping.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            if (tag.topspeed > -1)
            {
                attribute       = xmlDoc.CreateAttribute("topspeed");
                attribute.Value = tag.topspeed.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("sound");
            attribute.Value = tag.sound;
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <Vox>() != null)
        {
            Vox tag = (Vox)currentObject.GetComponent <Vox>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "vox", "");
            enrichXmlWithGameObjectAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("file");
            attribute.Value = tag.file.Replace(XmlImporter.getLevelFolder(tag.file), "LEVEL");
            node.Attributes.Append(attribute);

            if (!String.IsNullOrEmpty(tag.voxObject))
            {
                attribute       = xmlDoc.CreateAttribute("object");
                attribute.Value = tag.voxObject;
                node.Attributes.Append(attribute);
            }


            attribute       = xmlDoc.CreateAttribute("prop");
            attribute.Value = tag.dynamic ? "true" : "false";
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <VoxBox>() != null)
        {
            VoxBox tag = (VoxBox)currentObject.GetComponent <VoxBox>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "voxbox", "");
            enrichXmlWithGameObjectAttributes(xmlDoc, tag, node);
            Debug.Log(tag.position);

            XmlAttribute attribute = xmlDoc.CreateAttribute("color");
            attribute.Value = $"{tag.color.r} {tag.color.g} {tag.color.b}".Replace(",", ".");
            node.Attributes.Append(attribute);

            attribute       = xmlDoc.CreateAttribute("prop");
            attribute.Value = tag.dynamic ? "true" : "false";
            node.Attributes.Append(attribute);
        }
        else if (currentObject.GetComponent <TeardownJoint>() != null)
        {
            TeardownJoint tag = (TeardownJoint)currentObject.GetComponent <TeardownJoint>();
            node = xmlDoc.CreateNode(XmlNodeType.Element, "joint", "");
            enrichXmlWithTransformAttributes(xmlDoc, tag, node);

            XmlAttribute attribute = xmlDoc.CreateAttribute("type");
            attribute.Value = tag.type.ToString().ToLower();
            node.Attributes.Append(attribute);

            if (tag.limits != null && !$"{tag.limits.x} {tag.limits.y}".Replace(",", ".").Equals("0 0"))
            {
                attribute       = xmlDoc.CreateAttribute("limits");
                attribute.Value = $"{tag.limits.x} {tag.limits.y}".Replace(",", ".");
                node.Attributes.Append(attribute);
            }

            attribute       = xmlDoc.CreateAttribute("size");
            attribute.Value = tag.size.ToString().Replace(",", ".");
            node.Attributes.Append(attribute);

            if (tag.rotstrength >= 0)
            {
                attribute       = xmlDoc.CreateAttribute("rotstrength");
                attribute.Value = tag.rotstrength.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }
            if (tag.rotspring >= 0)
            {
                attribute       = xmlDoc.CreateAttribute("rotspring");
                attribute.Value = tag.rotspring.ToString().Replace(",", ".");
                node.Attributes.Append(attribute);
            }
        }

        if (node != null)
        {
            foreach (Transform child in currentObject)
            {
                exportToXML(xmlDoc, child, node);
            }

            if (parent == null)
            {
                xmlDoc.AppendChild(node);
            }
            else
            {
                parent.AppendChild(node);
            }
        }
    }