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

            int row            = chunk.GetMaxRow() + 1;
            int startingColumn = chunk.GetMinColumn();
            int endColumn      = chunk.GetMaxColumn();

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

            for (int x = startingColumn; x <= endColumn; ++x)
            {
                int vertexTopLeft = x + (row * 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);
        }