示例#1
0
        public static BuilderNode AddBuilderNode(Vector3 _position)
        {
            GameObject newNode = new GameObject("Builder Node " + (BuilderData.Data.builderNodes.Count + 1).ToString(),
                                                new System.Type[] { typeof(BuilderNode) });

            newNode.transform.SetParent(BuilderData.Data.builderNodeParent);
            newNode.transform.position = _position;
            BuilderNode builderNodeComp = newNode.GetComponent <BuilderNode> ();

            BuilderData.Data.builderNodes.Add(builderNodeComp);
            builderNodeComp.builderNodeId = BuilderData.Data.builderNodes.Count;

            int row = BuilderData.Data.linkGraph.Count;

            BuilderData.Data.linkGraph.Add(new List <int> ());

            for (int i = 0; i < row + 1; i++)
            {
                if (i != row)
                {
                    BuilderData.Data.linkGraph [row].Add(999);
                }
                else
                {
                    BuilderData.Data.linkGraph [row].Add(0);
                }
            }

            return(builderNodeComp);
        }
示例#2
0
        public static GameObject Extrude(BuilderNode _startNode)
        {
            BuilderNode endNode = AddBuilderNode(_startNode.transform.position + Vector3.forward * 1f);

            LinkNode(_startNode.builderNodeId, endNode.builderNodeId);

            return(endNode.gameObject);
        }
示例#3
0
        public static void OnDeleteNode(BuilderNode _node)
        {
            BuilderData.Data.builderNodes.RemoveAt(_node.builderNodeId - 1);
            BuilderData.Data.linkGraph.RemoveAt(_node.builderNodeId - 1);
            for (int i = _node.builderNodeId - 1; i < BuilderData.Data.linkGraph.Count; i++)
            {
                BuilderData.Data.linkGraph [i].RemoveAt(_node.builderNodeId - 1);
            }
            for (int i = _node.builderNodeId - 1; i < BuilderData.Data.linkGraph.Count; i++)
            {
                BuilderData.Data.builderNodes [i].builderNodeId--;
                BuilderData.Data.builderNodes [i].name = "Builder Node " + BuilderData.Data.builderNodes [i].builderNodeId;
            }

            RefreshLinkGraph();
            RefreshLineSetGroup();
        }
示例#4
0
        public static BuilderNode CreateRootNode(Vector3 _position)
        {
            GameObject newNode = new GameObject("Builder Node " + (BuilderData.Data.builderNodes.Count + 1).ToString(),
                                                new System.Type[] { typeof(BuilderNode) });

            newNode.transform.SetParent(BuilderData.Data.builderNodeParent);
            newNode.transform.position = _position;
            BuilderNode builderNodeComp = newNode.GetComponent <BuilderNode> ();

            BuilderData.Data.builderNodes.Add(builderNodeComp);

            builderNodeComp.builderNodeId = BuilderData.Data.builderNodes.Count;

            BuilderData.Data.linkGraph.Add(new List <int> ());
            BuilderData.Data.linkGraph [0].Add(0);

            return(builderNodeComp);
        }
示例#5
0
        public static void Load()
        {
            BuilderData.Data.ClearData();

            string lfd = EditorUtility.OpenFilePanelWithFilters("加载数据库文件", "", new string[] { "(*.db)", "db" });

            if (lfd != "")
            {
                BuilderNodeDAO.DAO.Load(lfd);
                LinkInfoDAO.DAO.Load(lfd);
            }
            else
            {
                return;
            }

            foreach (BuilderNodeDAO.BuilderNodeRecord r in BuilderNodeDAO.DAO.builderNodeRecords)
            {
                BuilderNode newNode = BuilderCore.CreateNode(String2Vector3(r.position));
                newNode.gameObject.transform.rotation = String2Quaternion(r.rotation);
                newNode.builderNodeId = r.id;
                switch (r.type)
                {
                case 1:
                    newNode.builderNodeType = BuilderNodeType.Section;
                    break;

                case 2:
                    newNode.builderNodeType = BuilderNodeType.Intersection;
                    break;
                }
            }
            foreach (LinkInfoDAO.LinkInfoRecord l in LinkInfoDAO.DAO.linkInfoRecords)
            {
                BuilderData.Data.linkGraph [l.fromId] [l.toId] = l.distance;
            }

            RefreshLineSetGroup();
            RefreshSectionNodes();
        }
示例#6
0
 public static void MergeIntersection()
 {
     for (int i = 0; i < BuilderData.Data.lineSetMap.Count; i++)
     {
         for (int j = i + 1; j < BuilderData.Data.lineSetMap.Count; j++)
         {
             if (!BuilderData.Data.lineSetMap [i].startNode.Equals(BuilderData.Data.lineSetMap [j].startNode) &&
                 !BuilderData.Data.lineSetMap [i].endNode.Equals(BuilderData.Data.lineSetMap [j].endNode) &&
                 !BuilderData.Data.lineSetMap [i].startNode.Equals(BuilderData.Data.lineSetMap [j].endNode) &&
                 !BuilderData.Data.lineSetMap [i].endNode.Equals(BuilderData.Data.lineSetMap [j].startNode))
             {
                 Line line = DistBetweenLines(BuilderData.Data.lineSetMap [i].GetLine,
                                              BuilderData.Data.lineSetMap [j].GetLine);
                 if (line.Length < BuilderTool.Settings.mergeIntersectionThreshold)
                 {
                     Debug.Log(BuilderData.Data.lineSetMap [i].startNode.name + "-" + BuilderData.Data.lineSetMap [i].endNode.name
                               + " compares to " + BuilderData.Data.lineSetMap [j].startNode.name + "-" + BuilderData.Data.lineSetMap [j].endNode.name
                               + " distance = " + line.Length);
                     BuilderNode newNode = AddBuilderNode(line.end);
                     LinkNode(BuilderData.Data.lineSetMap [i].startNode.GetComponent <BuilderNode> ().builderNodeId,
                              newNode.builderNodeId);
                     LinkNode(BuilderData.Data.lineSetMap [i].endNode.GetComponent <BuilderNode> ().builderNodeId,
                              newNode.builderNodeId);
                     LinkNode(BuilderData.Data.lineSetMap [j].startNode.GetComponent <BuilderNode> ().builderNodeId,
                              newNode.builderNodeId);
                     LinkNode(BuilderData.Data.lineSetMap [j].endNode.GetComponent <BuilderNode> ().builderNodeId,
                              newNode.builderNodeId);
                     int p1_start = BuilderData.Data.lineSetMap [i].startNode.GetComponent <BuilderNode> ().builderNodeId;
                     int p1_end   = BuilderData.Data.lineSetMap [i].endNode.GetComponent <BuilderNode> ().builderNodeId;
                     int p2_start = BuilderData.Data.lineSetMap [j].startNode.GetComponent <BuilderNode> ().builderNodeId;
                     int p2_end   = BuilderData.Data.lineSetMap [j].endNode.GetComponent <BuilderNode> ().builderNodeId;
                     BreakLink(p1_start, p1_end);
                     BreakLink(p2_start, p2_end);
                     return;
                 }
             }
         }
     }
 }
示例#7
0
 public static void DeleteNode(BuilderNode _node)
 {
     DestroyImmediate(_node.gameObject);
 }