public bool AllocateRect(int width, int height, out RectInt uvs)
 {
     // Attempt to allocate.
     if (!m_Allocator.TryAllocate(width + m_2SidePadding, height + m_2SidePadding, out uvs))
     {
         return(false);
     }
     uvs = new RectInt(uvs.x + m_1SidePadding, uvs.y + m_1SidePadding, width, height);
     return(true);
 }
 public bool AllocateRect(int width, int height, out RectInt uvs)
 {
     // Attempt to allocate.
     if (!m_Allocator.TryAllocate(width + 2, height + 2, out uvs))
     {
         return(false);
     }
     uvs = new RectInt(uvs.x + 1, uvs.y + 1, width, height);
     return(true);
 }
Beispiel #3
0
        /// <summary>
        /// If the provided texture is already in the atlas, the uvs are returned immediately. Otherwise, if the
        /// texture passes the requirements (format, etc), it will be virtually added to the atlas and added to the
        /// list of textures to be committed.
        /// </summary>
        public bool TryGetLocation(Texture2D image, out RectInt uvs)
        {
            uvs = new RectInt();

            if (disposed)
            {
                LogDisposeError();
                return(false);
            }

            if (image == null)
            {
                return(false);
            }

            // Is the image already in the atlas?
            if (m_UVs.TryGetValue(image, out uvs))
            {
                return(true);
            }

            if (!IsTextureValid(image))
            {
                return(false);
            }

            // Attempt to allocate.
            RectInt alloc;

            if (!m_Allocator.TryAllocate(image.width + 2, image.height + 2, out alloc))
            {
                return(false);
            }
            uvs          = new RectInt(alloc.x + 1, alloc.y + 1, image.width, image.height);
            m_UVs[image] = uvs;

            // Add a blit instruction.
            m_PendingBlits.Add(new BlitInfo {
                src = image, x = uvs.x, y = uvs.y, addBorder = true
            });

            return(true);
        }
Beispiel #4
0
        /// <summary>
        /// If the provided texture is already in the atlas, the uvs are returned immediately. Otherwise, if the
        /// texture passes the requirements (format, etc), it will be virtually added to the atlas and added to the
        /// list of textures to be committed.
        /// </summary>
        public bool TryGetLocation(Texture2D image, out RectInt uvs)
        {
            uvs = new RectInt();

            if (disposed)
            {
                LogDisposeError();
                return(false);
            }

            if (image == null)
            {
                return(false);
            }

            // Is the image already in the atlas?
            if (m_UVs.TryGetValue(image, out uvs))
            {
                return(true);
            }

            if (!IsTextureValid(image))
            {
                return(false);
            }

            // Attempt to allocate.
            RectInt alloc;

            if (!m_Allocator.TryAllocate(image.width + 2, image.height + 2, out alloc))
            {
                return(false);
            }
            uvs          = new RectInt(alloc.x + 1, alloc.y + 1, image.width, image.height);
            m_UVs[image] = uvs;

            // Add a blit instruction.
            m_Blitter.QueueBlit(image, new RectInt(0, 0, image.width, image.height), new Vector2Int(uvs.x, uvs.y), true);

            return(true);
        }