// Start is called before the first frame update void Start() { //Test Sprite Graphics.PixelMatrix pixels = new Graphics.PixelMatrix(width, height, Color.white); Texture2D tex = new Texture2D(width, height); tex.SetPixels(pixels.pixels); sprite = Sprite.Create(tex, new Rect(0, 0, width, height), new Vector2(0.5f, 0.5f)); this.GetComponent <SpriteRenderer>().sprite = sprite; }
public void LoadData() { //Reset Dictionaries heights = new Dictionary <string, TerrainHeight>(); structures = new Dictionary <string, TerrainStructure>(); terrains = new Dictionary <string, TerrainType>(); biomes = new Dictionary <string, Biome>(); //TODO Do this in seperate function(probably similar versions will be needed) //Load decals string[] filePaths = Directory.GetFiles(@Application.streamingAssetsPath + "/Decals", "*.png", SearchOption.TopDirectoryOnly); Texture2D[] decalsRaw = new Texture2D[filePaths.Length]; for (int i = 0; i < filePaths.Length; i++) { //Get file WWW www = new WWW("file://" + filePaths[i]); decalsRaw[i] = www.texture; //Index of last '\' int l = filePaths[i].LastIndexOf('\\'); //Get name of file (with extension) decalsRaw[i].name = filePaths[i].Substring(l + 1); } //Load decals into a dictionary with PixelMatrix decals = new Dictionary <string, Graphics.PixelMatrix[]>(); for (int i = 0; i < decalsRaw.Length; i++) { //Rotation variants //TODO only process rotated versions if required in JSON //(very small optimization, also maybe not ideal if the same decal is used in a rotated and not rotated context) Graphics.PixelMatrix[] decalsArray = new Graphics.PixelMatrix[4]; decalsArray[0] = new Graphics.PixelMatrix(decalsRaw[i]); decalsArray[1] = Graphics.RotateSq(decalsArray[0], 1); decalsArray[2] = Graphics.RotateSq(decalsArray[0], 2); decalsArray[3] = Graphics.RotateSq(decalsArray[0], 3); decals.Add(decalsRaw[i].name, decalsArray); } //Load Terrain JSON files LoadHeight(); LoadTerrain(); LoadStructures(); LoadBiomes(); }