public static bool CreateBlankTexture(string path, bool alphaTransparency)
{
if (string.IsNullOrEmpty(path))
return false;
// Prepare blank texture
Texture2D texture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
// Create the texture asset
AssetDatabase.CreateAsset(texture, AssetDatabase.GenerateUniqueAssetPath(path));
// Clear the read-only flag in texture file attributes
if (!SPTools.RemoveReadOnlyFlag(path))
return false;
// Write the texture data
byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
bytes = null;
// Get the asset texture importer
TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
if (textureImporter == null)
return false;
TextureImporterSettings settings = new TextureImporterSettings();
textureImporter.ReadTextureSettings(settings);
settings.spriteMode = 2;
settings.readable = false;
settings.maxTextureSize = 4096;
settings.wrapMode = TextureWrapMode.Clamp;
settings.npotScale = TextureImporterNPOTScale.ToNearest;
settings.textureFormat = TextureImporterFormat.ARGB32;
settings.filterMode = FilterMode.Point;
settings.aniso = 4;
settings.alphaIsTransparency = alphaTransparency;
textureImporter.SetTextureSettings(settings);
textureImporter.textureType = TextureImporterType.Sprite;
AssetDatabase.SaveAssets();
SPTools.DoAssetReimport(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
return true;
}