Ejemplo n.º 1
0
        public UIRAtlasAllocator(int initialAtlasSize, int maxAtlasSize, int sidePadding = 1)
        {
            Assert.IsTrue(initialAtlasSize > 0 && initialAtlasSize <= maxAtlasSize);
            Assert.IsTrue(initialAtlasSize == Mathf.NextPowerOfTwo(initialAtlasSize));
            Assert.IsTrue(maxAtlasSize == Mathf.NextPowerOfTwo(maxAtlasSize));
            this.m_1SidePadding = sidePadding;
            this.m_2SidePadding = sidePadding << 1;
            this.< maxAtlasSize > k__BackingField   = maxAtlasSize;
            this.< maxImageWidth > k__BackingField  = maxAtlasSize;
            this.< maxImageHeight > k__BackingField = ((initialAtlasSize == maxAtlasSize) ? (maxAtlasSize / 2 + this.m_2SidePadding) : (maxAtlasSize / 4 + this.m_2SidePadding));
            this.virtualWidth  = initialAtlasSize;
            this.virtualHeight = initialAtlasSize;
            int num = UIRAtlasAllocator.GetLog2OfNextPower(maxAtlasSize) + 1;

            this.m_OpenRows = new UIRAtlasAllocator.Row[num];
            RectInt rect = new RectInt(0, 0, initialAtlasSize, initialAtlasSize);

            this.m_FirstUnpartitionedArea = UIRAtlasAllocator.AreaNode.Acquire(rect);
            this.BuildAreas();
        }
Ejemplo n.º 2
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);
        }