private static Texture2D CreateTexture(Texture2D[] textures, ref int?size, int padding, out Rect[] texRects, out int minAtlasSize, UITexturePacker.FreeRectChoiceHeuristic heuristic)
    {
        var result = new Texture2D(1, 1);

        minAtlasSize = GetMinAtlasSize(textures, size ?? 128, ref padding, size ?? 128, heuristic);
        Debug.Log("*************************** Min size = " + minAtlasSize + "  - " + DateTime.Now);
        NGUISettings.forceSquareAtlas = true;
        texRects = UITexturePackerSpec.PackTexturesSpec(result, textures, minAtlasSize, minAtlasSize, padding, minAtlasSize, heuristic);
        Debug.Log("*************************** texture packed - " + DateTime.Now);
        if (size == null)
        {
            int power = (int)Math.Round(Math.Log(minAtlasSize, 2));

            size = (int)Math.Pow(2, power);
        }
        if (size <= minAtlasSize)
        {
            TextureScale.Resize(result, size.Value, size.Value, InterpolationMode.HighQualityBicubic);
        }
        else
        {
            texRects = UITexturePackerSpec.PackTextures(result, textures, size.Value, size.Value, padding, size.Value);
        }

        return(result);
    }