public static Texture2D CreateTextureFile(ColorPalette palette, string path, int colorBlockSize) { Texture2D texture = palette.CreateTexture(colorBlockSize, colorBlockSize); byte[] bytesText = texture.EncodeToPNG(); File.WriteAllBytes(path, bytesText); AssetDatabase.Refresh(); TextureImporter importer = AssetImporter.GetAtPath(path) as TextureImporter; importer.spritePixelsPerUnit = 100; importer.textureType = TextureImporterType.Sprite; importer.filterMode = FilterMode.Point; importer.SaveAndReimport(); return(texture); }