예제 #1
0
    //Updated
    private void DrawNodeNet(ref bool elementClicked)
    {
        //Nodes
        for (int i = 0; i < creator.NNodes; i++)
        {
            DrawNode(creator.GetNode(i), ref elementClicked);
            DrawNodeID(i);
        }
        //Stretches
        for (int i = 0; i < creator.NStretches; i++)
        {
            Stretch   st     = creator.GetStretch(i);
            Vector3[] points = st.GetPoints();

            DrawHandler(st, ref elementClicked);

            DrawStretch(points);
            if (creator.displayNet)
            {
                DrawBezier(points, netDisplaySettings, st.IsIntersection());
            }
            DrawDeleteButton(st);
            if (netDisplaySettings.showArrows)
            {
                DrawArrow(st);
            }
            if (netDisplaySettings.showVertices)
            {
                DrawVertices(st);
            }
        }
    }
예제 #2
0
    public XmlSerialization(NodeNetCreator net)
    {
        string      path = EditorUtility.SaveFilePanel("Save Nodenet xml", Application.dataPath, "NewNodenet", "xml");
        XmlDocument doc  = new XmlDocument();
        XmlElement  root;
        XmlNode     netNode;

        if (File.Exists(path))
        {
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);

            doc.Load(fs);

            root = doc.DocumentElement;
            root.RemoveAll();

            netNode = doc.ChildNodes[1];

            fs.Close();
        }
        else
        {
            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(xmlDeclaration);

            netNode = doc.CreateElement(string.Empty, "net", string.Empty);
            doc.AppendChild(netNode);
        }

        XmlElement nodesNode = doc.CreateElement(string.Empty, "nodes", string.Empty);

        netNode.AppendChild(nodesNode);

        //Nodes
        for (int n = 0; n < net.NNodes; n++)
        {
            Node       node     = net.GetNode(n);
            Vector3    nodePos  = node.Pos;
            XmlElement nodeNode = doc.CreateElement(string.Empty, "node", string.Empty);
            {
                nodeNode.SetAttribute("x", nodePos.x.ToString());
                nodeNode.SetAttribute("y", nodePos.y.ToString());
                nodeNode.SetAttribute("z", nodePos.z.ToString());
            }
            nodesNode.AppendChild(nodeNode);
        }



        XmlElement stretchesNode = doc.CreateElement(string.Empty, "stretches", string.Empty);

        netNode.AppendChild(stretchesNode);

        //Stretches
        for (int s = 0; s < net.NStretches; s++)
        {
            Stretch st           = net.GetStretch(s);
            int     anchorAIndex = st.anchorAIndex;
            int     anchorBIndex = st.anchorBIndex;

            XmlElement stretchNode = doc.CreateElement(string.Empty, "stretch", string.Empty);
            {
                stretchNode.SetAttribute("a", anchorAIndex.ToString());
                stretchNode.SetAttribute("b", anchorBIndex.ToString());

                Vector3    controlA     = st.ControlA;
                XmlElement controlANode = doc.CreateElement(string.Empty, "controlA", string.Empty);
                {
                    controlANode.SetAttribute("x", controlA.x.ToString());
                    controlANode.SetAttribute("y", controlA.y.ToString());
                    controlANode.SetAttribute("z", controlA.z.ToString());
                }
                Vector3    controlB     = st.ControlB;
                XmlElement controlBNode = doc.CreateElement(string.Empty, "controlB", string.Empty);
                {
                    controlBNode.SetAttribute("x", controlB.x.ToString());
                    controlBNode.SetAttribute("y", controlB.y.ToString());
                    controlBNode.SetAttribute("z", controlB.z.ToString());
                }

                stretchNode.AppendChild(controlANode);
                stretchNode.AppendChild(controlBNode);

                stretchesNode.AppendChild(stretchNode);
            }
        }

        doc.Save(path);
        AssetDatabase.Refresh();
    }