コード例 #1
0
        /// <summary>
        /// Repair all the nodes in the layout
        /// </summary>
        public void RepairAllNodes()
        {
            Transform[] allChildren = GetComponentsInChildren <Transform>(true);
            foreach (Transform child in allChildren)
            {
                RoadNetworkNode rnn = child.GetComponent <RoadNetworkNode>();
                if (rnn != null)
                {
                    rnn.CheckNodeAreValid();
                    rnn.Details.CompressRoads();

                    for (int r = 0; r < rnn.Details.Roads.Count; r++)
                    {
                        RoadNetworkNode rnnInner = rnn.Details.Roads[r];
                        if (!rnnInner.HasLinksToNode(rnn))
                        {
                            Debug.Log("Node " + rnn.name + " links to " + rnnInner.name + " Linking them");
                            RoadNetworkLayout.AddRoadToNode(rnn, rnnInner);
                            rnn.Details.CompressRoads();
                            rnnInner.Details.CompressRoads();
                        }
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Add a road
        /// </summary>
        /// <param name="node">The node to add the road too</param>
        /// <param name="nodeToAdd">The node to add</param>
        public static void AddRoadToNode(RoadNetworkNode node, RoadNetworkNode nodeToAdd)
        {
            if (node.HasLinksToNode(nodeToAdd))
            {
                return;
            }

            int roadCount = UnionHelper.GetRoadCount(node.Details.Union) + 1;

            node.Details.Union = UnionHelper.SetRoadUnionTypeFromRoadCount(roadCount);

            node.CreateRoadArray();
            for (int r = 0; r < node.Details.Roads.Count; r++)
            {
                if (node.Details.Roads[r] == null)
                {
                    node.Details.Roads[r] = nodeToAdd;
                    node.Details.Modified = true;
                    return;
                }
            }
        }