- Home /
how to dispatch textures as tiles in one terrain
trying to fix this script that have no compiling errors, but it seems like running infinitly and unity seems not responding please help!
using UnityEngine; using System.Collections; using System;
public class LoadTexture : MonoBehaviour { public int X_Tile; public int Y_Tile; public Terrain MyTerrain; public SplatPrototype[] splatPrototypes; void Start() { int Splats;
Splats = MyTerrain.terrainData.splatPrototypes.Length;
if (X_Tile * Y_Tile == Splats-1) {
Loadtextures (MyTerrain.terrainData,Splats);
}
}
void Loadtextures(TerrainData TerrD,int Splats)
{ float TileWidth;
float TileHeight;
int S=1;
int GridX=0;
int GridY = 0;
TileWidth = TerrD.alphamapWidth /X_Tile ;
TileHeight = TerrD.alphamapHeight / Y_Tile ;
Debug.Log ("TileWidth="+TileWidth);
Debug.Log ("TileHeight="+TileHeight);
Debug.Log ("alphamapWidth="+TerrD.alphamapWidth);
//Get Alphamps
float[, ,] alphas = TerrD.GetAlphamaps (0, 0, TerrD.alphamapWidth, TerrD.alphamapHeight);
// Relaod and reseize Splats
//SplatPrototype[] newSplatPrototypes = new SplatPrototype[Splats];
// for ( S=1; S<Splats; S++) {
// newSplatPrototypes[S]=new SplatPrototype ();
// newSplatPrototypes[S].texture = TerrD.splatPrototypes[S].texture ;
// newSplatPrototypes[S].tileSize = new Vector2 (TileWidth, TileHeight);
// }
//splatPrototypes = newSplatPrototypes;
//TerrD.RefreshPrototypes ();
//MyTerrain.Flush ();
// Dispatching textures
try {
for (int i = 0; i < TerrD.alphamapWidth ; i++)
{
GridX =Mathf.RoundToInt ( i/TileWidth);
for (int j =0; j <TerrD.alphamapHeight ; j++)
{ GridY = Mathf.RoundToInt ( j/TileHeight);
//for each point of mask do:
//paint all from old texture to new texture (saving already painted in new texture)
S= GridY*X_Tile -GridX;
Debug.Log ("GridX="+GridX);
Debug.Log ("GridY="+GridY);
Debug.Log ("S="+S);
alphas [j,i, S] = 1.0f;
//set old texture mask to zero
alphas [j,i, 0] = 0.0f;
}
}
// apply the new alpha
TerrD.SetAlphamaps (0, 0, alphas);
}
catch
{Debug.LogError("erreur");
}
}
}
Comment