Create and save a Atlas texture with scripting

I want to do this:

  1. Create a texture with the PackageTexture funtion
  2. Save that texture in the project.

Please, help me.

I find a solution for my problem:

    Texture texture = new Texture2D(maximunAtlasSize, maximunAtlasSize);
    texture.PackTextures(frames, padding, maximunAtlasSize);
    texture.name = "New Atlas";
    texture.Apply();

    if(!Directory.Exists(Application.dataPath + "/Atlases"))
        Directory.CreateDirectory(Application.dataPath + "/Atlases");

    FileStream fs = new FileStream(Application.dataPath + "/Atlases/" + texture.name + ".png", FileMode.Create);
    BinaryWriter bw = new BinaryWriter(fs);
    bw.Write(texture.EncodeToPNG());
    bw.Close();
    fs.Close();

Thanks .NET :D.