/// <summary> /// Returns terrain names of terrains that intersect with the given bounds object /// </summary> /// <param name="bounds">A bounds object to check against the terrains. Needs to be in absolute world space position, mind the current origin offset!</param> /// <returns></returns> public static string[] GetTerrainsIntersectingBounds(BoundsDouble bounds) { //Reduce the bounds size a bit to prevent selecting terrains that are perfectly aligned with the bounds border //-this leads to too many terrains being logged as affected by an operation otherwise. Bounds intersectingBounds = new BoundsDouble(); intersectingBounds.center = bounds.center; intersectingBounds.size = bounds.size - new Vector3Double(0.001f, 0.001f, 0.001f); if (GaiaUtils.HasDynamicLoadedTerrains()) { GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager(); if (sessionManager == null) { Debug.LogError("Trying to get terrains that intersect with bounds, but there is no session manager in scene."); return(null); } return(TerrainLoaderManager.TerrainScenes.Where(x => x.m_bounds.Intersects(intersectingBounds)).Select(x => x.GetTerrainName()).ToArray()); } else { List <string> affectedTerrainNames = new List <string>(); foreach (Terrain t in Terrain.activeTerrains) { if (intersectingBounds.Intersects(TerrainHelper.GetWorldSpaceBounds(t))) { affectedTerrainNames.Add(t.name); } } return(affectedTerrainNames.ToArray()); } }