private void NavCellsFromXML(XmlNode navMeshXml) { string[] navMeshStringRows = navMeshXml.InnerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); uint rowCount = (uint)navMeshStringRows.Length; uint colomnCount = (uint)navMeshStringRows[0].Length; // Compute derived room properties float roomWidth = (float)colomnCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE; float roomHeight = (float)rowCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE; BitArray navCellData = new BitArray((int)(rowCount * colomnCount)); int navMeshDataIndex = 0; foreach (string rowString in navMeshStringRows) { foreach (char c in rowString) { navCellData[navMeshDataIndex] = (c == '1'); ++navMeshDataIndex; } } m_colomnCount = colomnCount; m_rowCount = rowCount; m_nonEmptyNavCellCount = 0; m_roomKey = null; m_boundingBox = new AABB3d(); m_boundingBox.SetBounds2d(-roomWidth / 2.0f, -roomHeight / 2.0f, roomWidth / 2.0f, roomHeight / 2.0f); NavMesh.BuildNavCellConnectivityGrid( colomnCount, rowCount, navCellData, out m_navCells, out m_nonEmptyNavCellCount); }
private void NavCellsFromCompressedRawByteArray( byte[] compressedNavCells) { byte[] header = new byte[COMPRESSED_DATA_HEADER_BYTE_COUNT]; byte[] uncompressed = CompressionUtilities.RunLengthDecodeByteArray( compressedNavCells, CompressionUtilities.eEncodeType.Zeros, header); BitArray navCellData = new BitArray(uncompressed); // Read out the header Debug.Assert(COMPRESSED_DATA_HEADER_BYTE_COUNT == 2); uint colomnCount = (uint)header[0]; uint rowCount = (uint)header[1]; // Compute derived room properties int navCellCount = (int)(rowCount * colomnCount); float roomWidth = (float)colomnCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE; float roomHeight = (float)rowCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE; // Initialize the nav cell derived data m_colomnCount = colomnCount; m_rowCount = rowCount; m_nonEmptyNavCellCount = 0; m_roomKey = null; m_boundingBox = new AABB3d(); m_boundingBox.SetBounds2d(-roomWidth / 2.0f, -roomHeight / 2.0f, roomWidth / 2.0f, roomHeight / 2.0f); // Truncate extra bits added due to the bit array getting rounded up to the nearest byte navCellData.Length = navCellCount; // Compute the connectivity data from the nav cell bit array NavMesh.BuildNavCellConnectivityGrid( colomnCount, rowCount, navCellData, out m_navCells, out m_nonEmptyNavCellCount); }