Editor/Tools/SetHeightTool.cs

Editor tool class for the SubTerrain editor. It defines a "Set Height" brush tool that uses the Flatten sculpt mode and, when painting, sets the flatten target height from the brush settings scaled by the terrain height before delegating to the base painting logic.

using Sandbox;

namespace Editor.SubTerrain;

/// <summary>
/// Set Height tool. Like Flatten, but targets the absolute world height in brush settings.
/// </summary>
[Title( "Set Height" )]
[Icon( "straighten" )]
[Alias( "subterrain_set_height" )]
[Group( "1" )]
[Order( 6 )]
public class SubSetHeightTool : SubTerrainBaseBrushTool
{
	public SubSetHeightTool( SubTerrainTool parent ) : base( parent )
	{
		Mode = SubTerrainSculptMode.Flatten;
	}

	protected override void OnPaint( Terrain terrain, SubTerrainPaintParameters paint )
	{
		paint.FlattenHeight = paint.BrushSettings.TargetHeight / terrain.Storage.TerrainHeight;
		base.OnPaint( terrain, paint );
	}
}