示例#1
0
        protected virtual void Dispose(bool disposing)
        {
            bool disposed = this.disposed;

            if (!disposed)
            {
                if (disposing)
                {
                    for (int i = 0; i < this.m_OpenRows.Length; i++)
                    {
                        UIRAtlasAllocator.Row row = this.m_OpenRows[i];
                        bool flag = row != null;
                        if (flag)
                        {
                            row.Release();
                        }
                    }
                    this.m_OpenRows = null;
                    UIRAtlasAllocator.AreaNode next;
                    for (UIRAtlasAllocator.AreaNode areaNode = this.m_FirstUnpartitionedArea; areaNode != null; areaNode = next)
                    {
                        next = areaNode.next;
                        areaNode.Release();
                    }
                    this.m_FirstUnpartitionedArea = null;
                }
                this.disposed = true;
            }
        }
示例#2
0
 public static UIRAtlasAllocator.Row Acquire(int offsetX, int offsetY, int width, int height)
 {
     UIRAtlasAllocator.Row row = UIRAtlasAllocator.Row.s_Pool.Get();
     row.offsetX = offsetX;
     row.offsetY = offsetY;
     row.width   = width;
     row.height  = height;
     row.Cursor  = 0;
     return(row);
 }
示例#3
0
        private bool TryPartitionArea(UIRAtlasAllocator.AreaNode areaNode, int rowIndex, int rowHeight, int minWidth)
        {
            RectInt rect = areaNode.rect;
            bool    flag = rect.height < rowHeight || rect.width < minWidth;
            bool    result;

            if (flag)
            {
                result = false;
            }
            else
            {
                UIRAtlasAllocator.Row row = this.m_OpenRows[rowIndex];
                bool flag2 = row != null;
                if (flag2)
                {
                    row.Release();
                }
                row = UIRAtlasAllocator.Row.Acquire(rect.x, rect.y, rect.width, rowHeight);
                this.m_OpenRows[rowIndex] = row;
                rect.y      += rowHeight;
                rect.height -= rowHeight;
                bool flag3 = rect.height == 0;
                if (flag3)
                {
                    bool flag4 = areaNode == this.m_FirstUnpartitionedArea;
                    if (flag4)
                    {
                        this.m_FirstUnpartitionedArea = areaNode.next;
                    }
                    areaNode.RemoveFromChain();
                    areaNode.Release();
                }
                else
                {
                    areaNode.rect = rect;
                }
                result = true;
            }
            return(result);
        }
示例#4
0
        public bool TryAllocate(int width, int height, out RectInt location)
        {
            bool result;

            using (UIRAtlasAllocator.s_MarkerTryAllocate.Auto())
            {
                location = default(RectInt);
                bool disposed = this.disposed;
                if (disposed)
                {
                    result = false;
                }
                else
                {
                    bool flag = width < 1 || height < 1;
                    if (flag)
                    {
                        result = false;
                    }
                    else
                    {
                        bool flag2 = width > this.maxImageWidth || height > this.maxImageHeight;
                        if (flag2)
                        {
                            result = false;
                        }
                        else
                        {
                            int log2OfNextPower       = UIRAtlasAllocator.GetLog2OfNextPower(Mathf.Max(height - this.m_2SidePadding, 1));
                            int rowHeight             = (1 << log2OfNextPower) + this.m_2SidePadding;
                            UIRAtlasAllocator.Row row = this.m_OpenRows[log2OfNextPower];
                            bool flag3 = row != null && row.width - row.Cursor < width;
                            if (flag3)
                            {
                                row = null;
                            }
                            bool flag4 = row == null;
                            if (flag4)
                            {
                                for (UIRAtlasAllocator.AreaNode areaNode = this.m_FirstUnpartitionedArea; areaNode != null; areaNode = areaNode.next)
                                {
                                    bool flag5 = this.TryPartitionArea(areaNode, log2OfNextPower, rowHeight, width);
                                    if (flag5)
                                    {
                                        row = this.m_OpenRows[log2OfNextPower];
                                        break;
                                    }
                                }
                                bool flag6 = row == null;
                                if (flag6)
                                {
                                    result = false;
                                    return(result);
                                }
                            }
                            location    = new RectInt(row.offsetX + row.Cursor, row.offsetY, width, height);
                            row.Cursor += width;
                            Assert.IsTrue(row.Cursor <= row.width);
                            this.physicalWidth  = Mathf.NextPowerOfTwo(Mathf.Max(this.physicalWidth, location.xMax));
                            this.physicalHeight = Mathf.NextPowerOfTwo(Mathf.Max(this.physicalHeight, location.yMax));
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }