SimpleSpritePackerEditor.SPTools.ImportTexture C# (CSharp) Method

ImportTexture() public static method

Imports a texture as asset.
public static ImportTexture ( string path, Texture2D texture ) : bool
path string Path.
texture UnityEngine.Texture2D Texture.
return bool
        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;
        }