コード例 #1
0
        /// <summary>
        /// Uses A* algorithm to find a path from disconnected clusters to main cluster and
        /// convert nodes on that path to floors.
        /// </summary>
        public void ConnectClusters()
        {
            for (int clusterIndex = 0; clusterIndex < Clusters.Count; clusterIndex++)
            {
                if (clusterIndex != mainClusterIndex)
                {
                    NodeCluster origCluster = Clusters [clusterIndex];

                    Node origCell = origCluster.Nodes [(int)((origCluster.Nodes.Count - 1) * Random.value)];

                    Node destCell = MainCluster.Nodes [(int)((MainCluster.Nodes.Count - 1) * Random.value)];

                    List <Node> path = pathManager.GetShortestPath(origCell, destCell, 1f, true);


                    if (path == null || path.Count == 0)
                    {
                        if (Utilities.instance.IsDebug)
                        {
                            Debug.Log(SCRIPT_NAME + ": no path found");
                        }
                    }
                    else
                    {
                        ConstructPath(path, NodeType.Background);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Iterats through each cluster and returns the index of the cluster with the largest size.
        /// </summary>
        /// <returns>The main cluster index.</returns>
        public void CalculateMainCluster()
        {
            int newMainClusterIndex = -1;
            int maxClusterSize      = 0;

            for (int i = 0; i < Clusters.Count; i++)
            {
                NodeCluster cluster = Clusters [i];

                int cellCount = cluster.Nodes.Count;

                if (cellCount > maxClusterSize)
                {
                    maxClusterSize      = cellCount;
                    newMainClusterIndex = i;
                }
            }

            mainClusterIndex = newMainClusterIndex;
        }