private void PopulateGrid() { int blocked = 0; g_WalkedOnNodes = new Dictionary <INPCPathfinder, NavNode>(); g_GridScale = 1f / (float)GridScale; float nodeDiameter = g_NodeRadius * 2 * g_GridScale; GridDimensions.x = Mathf.RoundToInt(transform.localScale.x / nodeDiameter); GridDimensions.y = Mathf.RoundToInt(transform.localScale.z / nodeDiameter); int tilesX = (int)GridDimensions.x, tilesY = (int)GridDimensions.y; g_Grid = new NavNode[tilesX, tilesY]; Vector3 gridWorldBottom = (transform.position - (transform.right * GridDimensions.x / 2) - (transform.forward * GridDimensions.y / 2) + new Vector3(g_NodeRadius, 0.0f, g_NodeRadius)) * g_GridScale; for (int row = 0; row < tilesX; ++row) { for (int col = 0; col < tilesY; ++col) { NavNode node = new NavNode( gridWorldBottom + (transform.right * (nodeDiameter) * row) + transform.forward * (nodeDiameter) * col, new Vector2(row, col), transform.up, BlockingHeight, true, g_NodeRadius * g_GridScale, this); if (!node.IsWalkable()) { blocked++; node.NodeStatus = NavNode.NODE_STATUS.BLOCKED; } g_Grid[row, col] = node; } } if (LoadFromFile && Application.isPlaying) { WriteGridToFile = false; ReadGridFromFile(); } else { int targetBlocked = (int)(MinimunBlocked * (tilesX * tilesY)); RandomizeHardWalkingAreas(RandomHeavyAreas, 31); RandomizeHighways(RandomHighways); if (AddBlockerOnScene && (blocked < targetBlocked)) { RandomizeBlockers(targetBlocked - blocked); AddBlockerOnScene = false; } } }