private static void createFeatureTexture(IKeyNameable item, Texture2D to, int x, int y)
        {
            Color background = Color.gray;
            var textY = y + TextureSize;
            if (item is TerrainBiome) {
                textY -= FontSize;
            } else if (item is TerrainLandform) {
                textY -= FontSize*2;
                background=new Color(0,0,0,0);
            } else if (item is TerrainVegetation) {
                textY -= FontSize*3;
                background=new Color(0,0,0,0);
            }

            for (int i = 0; i < TextureSize; i++) {
                for (int j = 0; j < TextureSize; j++) {
                    to.SetPixel(x + j, y + i, background);
                }
            }
            
            //to.SetPixel(x + TextureSize - 1, y , Color.green);
            //to.SetPixel(x, y + TextureSize - 1 , Color.magenta);
            int maxI = item.Name.Length<TextureSize/FontSize-1?item.Name.Length:TextureSize/FontSize-1;
            for (int i = 0; i < maxI; i++) {
                copyLetter(FontAtlas, to, x + FontSize * i, textY, item.Name[i], Color.red);
            }
        }
        public static void InitTexture()
        {
            FontAtlas = (Texture2D) Resources.Load("Font", typeof(Texture2D));

            foreach (var item in _texturedFeatures) {
                if (!TextureLocation.Applicable(item.Key.Flavour)) {
                    TextureLocation.AddFlavour(item.Key.Flavour);
                }
            }
            TextureLocation.Register();
            TextureLocation.Freeze();
            
            
            byte widthAmount = 8;
            byte heightAmount = (byte) (_texturedFeatures.Count / widthAmount + 1);
            
            
            TextureAtlas = new Texture2D(TextureSize * widthAmount, TextureSize * heightAmount, TextureFormat.ARGB32, false);
            
            for (byte i = 0; i < widthAmount; i++) {
                for (byte j = 0; j < heightAmount; j++) {
                    var index = i * heightAmount + j ;
                    Debug.Log($"{i} {j} {index} {_texturedFeatures.Count}");
                    if (index == _texturedFeatures.Count)  goto breakLocation;
                    IKeyNameable item = _texturedFeatures[index];
                    createFeatureTexture(item, TextureAtlas, i * TextureSize, j * TextureSize);
                    item.Key.Set(TextureLocation, new TextureLocation(i*TextureSize/(float)TextureAtlas.width, (i+1)*TextureSize/(float)TextureAtlas.width, j*TextureSize/(float)TextureAtlas.height, (j+1)*TextureSize/(float)TextureAtlas.height));
                }
            }
            breakLocation: ;

            TextureAtlas.wrapMode = TextureWrapMode.Clamp;
            TextureAtlas.anisoLevel = 0;
            TextureAtlas.filterMode = FilterMode.Point;
            
            TextureAtlas.Apply();
            /*byte[] bytes = TextureAtlas.EncodeToPNG();
            var rnd = new System.Random();
            File.WriteAllBytes("C:\\Users\\sirati97\\Desktop\\" + rnd.Next() + ".png", bytes);/**/
            
            
            Debug.Log ("Done creating atlas");

        }
 public static void TerrainHook(IKeyNameable item)
 {
     _texturedFeatures.Add(item);
 }
 private void TerrainHook(IKeyNameable item)
 {
     //ResourceManager.Instance.LoadResource()
 }