I am currently using the following function, but it does not seem efficient enough, so i am also looking for a better solution.
// Load specified texture and only that texture in given terrain
void LoadTerrain(TerrainData terrain_data, int texture_level) {
float[, ,] alphas = terrain_data.GetAlphamaps(0, 0, terrain_data.alphamapWidth, terrain_data.alphamapHeight);
// make sure every grid on the terrain is modified
for (int i = 0; i < terrain_data.alphamapWidth; i++) {
for (int j = 0; j < terrain_data.alphamapHeight; j++) {
// make sure only set layer is visible
for (int k = 0; k < terrain_data.alphamapLayers; k++) {
if (k == texture_level) {
alphas[i, j, k] = 1;
} else {
alphas[i, j, k] = 0;
}
}
}
}
// apply the new alpha
terrain_data.SetAlphamaps(0, 0, alphas);
}
a little upgraded script that allows to change texture without full repainting, e.g. it saves paint map and changes texture.