public void AdjustSize(int oriWidth, int oriHeight, int deltaW, int deltaH, out int adjustx, out int adjusty)
        {
            adjustx = adjusty = 0;
            int adjustXleft = 0, adjustYleft = 0, adjustXRight = 0, adjustYRight = 0;

            if (imageId == -1 || left == null)
            {
                if (rect.x + rect.width == oriWidth)
                {
                    rect.width += deltaW;
                    adjustx     = deltaW;
                }
                if (rect.y + rect.height == oriHeight)
                {
                    rect.height += deltaH;
                    adjusty      = deltaH;
                }
            }
            else
            {
                left.AdjustSize(oriWidth, oriHeight, deltaW, deltaH, out adjustXleft, out adjustYleft);
                right.AdjustSize(oriWidth, oriHeight, deltaW, deltaH, out adjustXRight, out adjustYRight);

                adjustx      = Mathf.Max(adjustXleft, adjustXRight);
                rect.width  += adjustx;
                adjusty      = Mathf.Max(adjustYleft, adjustYRight);
                rect.height += adjusty;
            }
        }
        static ImagePackNode InternalPack(RectInt[] rects, int padding)
        {
            var sortedRects = new ImagePackRect[rects.Length];

            for (int i = 0; i < rects.Length; ++i)
            {
                sortedRects[i]       = new ImagePackRect();
                sortedRects[i].rect  = rects[i];
                sortedRects[i].index = i;
            }
            Array.Sort <ImagePackRect>(sortedRects);
            var root = new ImagePackNode();

            root.rect = new RectInt(0, 0, 32, 32);

            for (int i = 0; i < rects.Length; ++i)
            {
                if (!root.Insert(sortedRects[i], padding)) // we can't fit
                {
                    int newWidth = 0, newHeight = 0;
                    if (root.rect.width < root.rect.height)
                    {
                        newWidth = (int)NextPowerOfTwo((ulong)root.rect.width + 1);
                    }
                    else
                    {
                        newHeight = (int)NextPowerOfTwo((ulong)root.rect.height + 1);
                    }
                    if (newWidth > k_MaxTextureSize || newHeight > k_MaxTextureSize)
                    {
                        Debug.LogAssertion("unable to pack, reached max texture size");
                        break;
                    }

                    root.AdjustSize(newWidth, newHeight);
                    --i;
                }
            }
            return(root);
        }