Hiyas when I save a position to XML with:
if (File.Exists(filepath))
{
xmlDoc.Load(filepath);
XmlElement elmRoot = xmlDoc.DocumentElement;
elmRoot.RemoveAll(); // remove all inside the transforms node.
Transform[] Container = GameObject.Find(GameobjectContainer).GetComponentsInChildren<Transform>();
int i = 0;
foreach (Transform child in Container)
{
if (child != Container[0])
{
i++;
XmlElement elmMain = xmlDoc.CreateElement("GameObject");
XmlElement elmID = xmlDoc.CreateElement("ID");
elmID.InnerText = i.ToString();
XmlElement elmDat = xmlDoc.CreateElement("data");
elmDat.InnerText = child.name;
XmlElement elmPos = xmlDoc.CreateElement("position");
elmPos.InnerText = child.transform.position.ToString();
XmlElement elmRot = xmlDoc.CreateElement("rotation");
elmRot.InnerText = child.transform.rotation.eulerAngles.ToString();
XmlElement elmSca = xmlDoc.CreateElement("scale");
elmSca.InnerText = child.transform.localScale.ToString();
elmMain.AppendChild(elmID);
elmMain.AppendChild(elmDat);
elmMain.AppendChild(elmPos);
elmMain.AppendChild(elmRot);
elmMain.AppendChild(elmSca);
elmRoot.AppendChild(elmMain);
}
}
xmlDoc.Save(filepath); // save file.
}
the position, rotation and localscale is rounded to 0.1 - what’s the best way to avoid this?