public static bool ImportTexture(string path, Texture2D texture)
{
if (string.IsNullOrEmpty(path))
return false;
// Clear the read-only flag in texture file attributes
if (!SPTools.RemoveReadOnlyFlag(path))
return false;
byte[] bytes = texture.EncodeToPNG();
System.IO.File.WriteAllBytes(path, bytes);
bytes = null;
AssetDatabase.SaveAssets();
SPTools.DoAssetReimport(path, ImportAssetOptions.ForceSynchronousImport);
return true;
}