public static void AutoConnect() { bool flag = !TerrainUtility.HasValidTerrains(); if (!flag) { TerrainUtility.ClearConnectivity(); TerrainUtility.TerrainGroups terrainGroups = TerrainUtility.CollectTerrains(true); bool flag2 = terrainGroups == null; if (!flag2) { foreach (KeyValuePair <int, TerrainUtility.TerrainMap> current in terrainGroups) { TerrainUtility.TerrainMap value = current.Value; foreach (KeyValuePair <TerrainUtility.TerrainMap.TileCoord, Terrain> current2 in value.m_terrainTiles) { TerrainUtility.TerrainMap.TileCoord key = current2.Key; Terrain terrain = value.GetTerrain(key.tileX, key.tileZ); Terrain terrain2 = value.GetTerrain(key.tileX - 1, key.tileZ); Terrain terrain3 = value.GetTerrain(key.tileX + 1, key.tileZ); Terrain terrain4 = value.GetTerrain(key.tileX, key.tileZ + 1); Terrain terrain5 = value.GetTerrain(key.tileX, key.tileZ - 1); terrain.SetNeighbors(terrain2, terrain4, terrain3, terrain5); } } } } }
internal static TerrainUtility.TerrainGroups CollectTerrains(bool onlyAutoConnectedTerrains = true) { bool flag = !TerrainUtility.HasValidTerrains(); TerrainUtility.TerrainGroups result; if (flag) { result = null; } else { TerrainUtility.TerrainGroups terrainGroups = new TerrainUtility.TerrainGroups(); Terrain[] activeTerrains = Terrain.activeTerrains; for (int i = 0; i < activeTerrains.Length; i++) { Terrain t = activeTerrains[i]; bool flag2 = onlyAutoConnectedTerrains && !t.allowAutoConnect; if (!flag2) { bool flag3 = !terrainGroups.ContainsKey(t.groupingID); if (flag3) { TerrainUtility.TerrainMap terrainMap = TerrainUtility.TerrainMap.CreateFromPlacement(t, (Terrain x) => x.groupingID == t.groupingID && (!onlyAutoConnectedTerrains || x.allowAutoConnect), true); bool flag4 = terrainMap != null; if (flag4) { terrainGroups.Add(t.groupingID, terrainMap); } } } } result = ((terrainGroups.Count != 0) ? terrainGroups : null); } return(result); }