Can I generate Terrain with C# Script

How do I generate Terrain with C# Script?

I had a bit of trouble find the right information for this as well.
This might help you forward.
I haven’t set any height data in the terrainData by the way.

GameObject TerrainObj = new GameObject("TerrainObj");

TerrainData _TerrainData = new TerrainData();

_TerrainData.size = new Vector3(10, 600, 10);
_TerrainData.heightmapResolution = 512;
_TerrainData.baseMapResolution = 1024;
_TerrainData.SetDetailResolution(1024, 16);

int _heightmapWidth = _TerrainData.heightmapWidth;
int _heightmapHeight = _TerrainData.heightmapHeight;

TerrainCollider _TerrainCollider = TerrainObj.AddComponent<TerrainCollider>();
Terrain _Terrain2 = TerrainObj.AddComponent<Terrain>();

_TerrainCollider.terrainData = _TerrainData;
_Terrain2.terrainData = _TerrainData;

You can also just use this for at quicker solution, but with less control. It creates the terrain in a Gameobject for you, and add a terrain and collider components.

Gameobject _Terrain = Terrain.CreateTerrainGameObject(_TerrainData);

I don't know in detail but I assume you can. Check out the terrain toolkit. It seems to include sources.

Terrain seems to make use of TerrainData which contain get/set functions so it should be able to be editable even though I haven't done so myself.