public static Vector2D PixelSize(this Terrain terrain, TerrainControlType controlType) { Vector2D worldSize = (Vector2D)terrain.terrainData.size; int resolution = GetResolution(terrain, controlType); return(worldSize / (resolution - 1)); //since terrain size looses half pixel from both sides }
public static CoordRect PixelRect(this Terrain terrain, TerrainControlType controlType) /// Getting whole terrain pixel rect { int resolution = GetResolution(terrain, controlType); Vector2D pixelSize = PixelSize(terrain, controlType); return(new CoordRect( Mathf.RoundToInt(terrain.transform.position.x / pixelSize.x), Mathf.RoundToInt(terrain.transform.position.z / pixelSize.z), resolution, resolution)); }
public static int GetResolution(this Terrain terrain, TerrainControlType controlType) { TerrainData terrainData = terrain.terrainData; switch (controlType) { case TerrainControlType.Height: return(terrainData.heightmapResolution); case TerrainControlType.Splats: return(terrainData.alphamapResolution); case TerrainControlType.Grass: return(terrainData.detailResolution); default: return(0); } }
public static CoordRect PixelRect(this Terrain terrain, Vector2D worldPos, Vector2D worldSize, TerrainControlType controlType) /// Convering offset/size rect to pixel rect { Vector2D pixelSize = PixelSize(terrain, controlType); return(CoordRect.WorldToPixel(worldPos, worldSize, pixelSize)); }