Skip to main content

TerrainInfo

A class in Root.Township, the global namespace.

Singleton (SingletonBehaviour<TerrainInfo>.Instance) wrapping the world's Unity terrain: height, normal and steepness lookups in world coordinates, and the splat map. The server disables the terrain renderer.

Constructors​

MemberWhat it is
TerrainInfo()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
const int SplatMapDividerConstant 2. Probably the splat map's resolution divisor.
5 private and internal fields
MemberWhat it is
private static readonly int _SplatControlShader property ID of the terrain material's splat control texture.
private Texture2D instantiatedSplatRuntime copy of sourceSplat, made on first use of Splat.
private static Logger loggerLogger for this class.
private Texture2D sourceSplatThe splat map asset copied for Splat.
private Terrain terrainThe Unity Terrain on this object.

Properties​

MemberWhat it is
Vector3 Offset { get; private set; }World position of the terrain's corner.
Vector3 Size { get; private set; }Terrain size in world units.
Texture2D Splat { get; }A writable copy of the splat (texture blend) map. Made on first read and applied to the terrain material.
TerrainData TerrainData { get; private set; }The terrain data in use (a copy, except on Android).
Vector3 Unit { get; private set; }Size of one heightmap cell in world units.

Methods​

MemberWhat it is
float GetHeightAndNormalAtPosition(float x, float z, out Vector3 normal)Terrain height (world y) and surface normal at a world x and z.
float GetHeightAtPosition(TerrainAccess access, float x, float z)Terrain height at a world x and z. The TerrainAccess overload reads from that segment and does not add the terrain's y offset.
float GetHeightAtPosition(float x, float z)Terrain height at a world x and z. The TerrainAccess overload reads from that segment and does not add the terrain's y offset.
Vector3 GetNormalAtPosition(float x, float z)Surface normal at a world x and z.
TerrainAccess GetSegment(float x, float y, float width, float height, bool isHeight = true, bool isSplat = true)Gets a TerrainAccess for a rectangle or bounds, clamped to the heightmap, with heights and splat if asked.
TerrainAccess GetSegment(Bounds bounds, bool isHeight = true, bool isSplat = true)Gets a TerrainAccess for a rectangle or bounds, clamped to the heightmap, with heights and splat if asked.
float GetSteepnessAtPosition(float x, float z)Slope in degrees at a world x and z.
void InitializeEditor()Editor: reads the terrain data without copying it.
bool IsAbove(Vector3 point, float lenience = 0)True if the point is above the terrain, allowing some lenience.
protected override void Awake()Copies the terrain data (except on Android) and hooks it to the terrain and its collider.
1 private and internal method
MemberWhat it is
private void OnDestroy()Cleans up the copied splat texture and material, and destroys the copied terrain data (except on Android, which uses the original).

Used in​

Members of other types that take, return or hold a TerrainInfo: