How to assign texture position on the terrain by coding, not the GUI

hi, everybody.I wanna to create a terrain from database,that is, i wanna to read some Geological data from database and then, draw the terrain by coding, and in some position, i wanna to assign a texture, for example, i wanna to add a texture and it ranges from point (0, 0) to (100, 100). how can i make it?use the splatPrototypes ? and what does it mean?

First of all you need to change your World Coordinates to Terrain Coordinates, which you can read here:

http://answers.unity3d.com/questions/7686/how-can-i-perform-some-action-based-on-the-terrain-texture-currently-under-my-pla

with this x and y positions, you can the splatmapdata from this coordinates like this:

    TerrainData td = Terrain.activeTerrain.terrainData;
    float[,,] splatmapData = td.GetAlphamaps(x, y, 1, 1);

Now you have an array of your splatmapdata which is build up like this:

splatmapData[0,0,0];

splatmapData[0,0,1];

splatmapData[0,0,2];
splatmapData[0,0,3];

These are your first 4 textures that you can see in the Terrain Paint Menu, now you can assign a certain Texture to this position with for example:

splatmapData[0, 0, 0] = 1;

Now your first texture would be fully assigned to this point, but now what you have to do is assign all other textures to zero, because the sum must allways be 1.

Now when you have this you can do:

td.SetAlphamaps(cords[0], cords[1], splatmapData);

And thats the whole trick. Hope it made it a little clearer =)

I am not very clear about the point below:

splatmapData[0,0,0]; splatmapData[0,0,1]; splatmapData[0,0,2]; splatmapData[0,0,3];

These are your first 4 textures that you can see in the Terrain Paint Menu

In the terrain paint menu? do you mean the terrain editor's paint Texture feature?But i can not find the first 4 textures.

public void changeTexture(int x, int y, int textureNumber){

    TerrainData terrainData = Terrain.activeTerrain.terrainData;
    
       float[,,] splatmapData = terrainData.GetAlphamaps(x, y, 1, 1);
       //Set OFF all textures en coord (x,y)
       for (int i = 0; i < terrainData.alphamapLayers; i++) {
    			splatmapData[0, 0, i] = 0;
    		}
       //Set ON
       splatmapData[0, 0, textureNumber] = 1;
       terrainData.SetAlphamaps(x, y, splatmapData);
    }