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);
        }
Exemple #2
0
        private void ProcessNewChunk(NavMeshChunk chunk, NavMeshNode startingNode)
        {
            bool columnsAvail = true;
            bool rowsAvail    = true;

            chunk.AddNode(startingNode, true);

            chunkDictionary.Add(startingNode.VertexTopLeft, chunk);
            nodeDictionary.Remove(startingNode.VertexTopLeft);

            if (startingNode.TooSteep)
            {
                return;
            }

            //// TEMP!!!!!!!!!!!!!!!!!!!!
            //if (startingNode.VertexTopLeft == 0)
            //{
            //    int i = 5;
            //    i++;
            //}

            while (columnsAvail || rowsAvail)
            {
                if (columnsAvail)
                {
                    columnsAvail = AddNewColumnToChunk(chunk);
                }

                if (rowsAvail)
                {
                    rowsAvail = AddNewRowToChunk(chunk);
                }
            }

            // Once we've made it here, that means the current chunk cannot expand any more
        }