Exemple #1
0
        /// <summary>
        /// Attempts to add a new column to a NavMeshChunk
        /// </summary>
        /// <param name="chunk">Chunk to add a new column to</param>
        /// <returns>Whether or not the column was added</returns>
        private bool AddNewColumnToChunk(NavMeshChunk chunk)
        {
            // Is this chunk's max column already at the end of the map
            if (chunk.GetMaxColumn() == this.terrainComp.Size - 1)
            {
                return(false);
            }

            int column      = chunk.GetMaxColumn() + 1;
            int startingRow = chunk.GetMinRow();
            int endRow      = chunk.GetMaxRow();

            List <NavMeshNode> nodesToAdd = new List <NavMeshNode>();

            for (int z = startingRow; z <= endRow; ++z)
            {
                int vertexTopLeft = column + (z * this.terrainComp.Size);

                NavMeshNode node;
                nodeDictionary.TryGetValue(vertexTopLeft, out node);

                // Node doesn't exist (was already chunked), so we fail at getting a new column
                if (node == null)
                {
                    return(false);
                }

                // If node is too steep then it cannot be part of this chunk
                if (node.TooSteep)
                {
                    return(false);
                }

                nodesToAdd.Add(node);
            }

            // If we made it this far, lets add the column into the chunk
            foreach (NavMeshNode node in nodesToAdd)
            {
                chunk.AddNode(node, true);
                chunkDictionary.Add(node.VertexTopLeft, chunk);
                nodeDictionary.Remove(node.VertexTopLeft);
            }

            return(true);
        }