Ejemplo n.º 1
0
        public void Import(NavMesh mesh, XmlNode node)
        {
            mesh.Name = node.Attributes.GetNamedItem("name").Value;
            mesh.DefaultMode = NavMesh.ParseTravelMode(node.Attributes.GetNamedItem("default_mode").Value);

            foreach (XmlNode childNode in node.ChildNodes)
            {
                switch (childNode.Name)
                {
                    case "mesh_node":
                        Vector3 meshNodePos;
                        string pos = childNode.Attributes.GetNamedItem("p").Value;
                        try
                        {
                            meshNodePos = Vector3.Parse(pos);
                        }
                        catch (Exception e)
                        {
                            throw new System.Xml.XmlException("Failed to parse mesh_node position: " + pos + ". Reason: " + e.Message);
                        }
                        mesh.AddNode(meshNodePos);
                    break;

                    case "mesh_edge":
                        int e1 = Convert.ToInt32(childNode.Attributes.GetNamedItem("e1").Value);
                        int e2 = Convert.ToInt32(childNode.Attributes.GetNamedItem("e2").Value);
                        TravelMode mode = mesh.DefaultMode;

                        try
                        {
                            mode = NavMesh.ParseTravelMode(childNode.Attributes.GetNamedItem("mode").Value);
                        } catch (Exception) {}

                        try
                        {
                            mesh.AddEdge(e1, e2, mode);
                        }
                        catch (System.ArgumentException)
                        {
                            m_log.Warn("[NavMeshSerializer]: Duplicate edge from: " + e1.ToString() + " to: " + e2.ToString() + ".");
                        }
                        break;

            //                    default:
            //                        throw new System.Xml.XmlException("Unknown xml element: " + childNode.Name + ".");
                }
            }
        }