public void Update(Texture2D image, RectInt rect) { if (disposed) { DisposeHelper.NotifyDisposedUsed(this); return; } Debug.Assert(image != null && rect.width > 0 && rect.height > 0); m_Blitter.QueueBlit(image, new RectInt(0, 0, image.width, image.height), new Vector2Int(rect.x, rect.y), true, Color.white); }
/// <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); }
/// <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 TryGetRect(Texture2D image, out RectInt uvs, Func <Texture2D, bool> filter = null) { 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 (filter != null && !filter(image)) { return(false); } // Attempt to allocate. if (!AllocateRect(image.width, image.height, out uvs)) { return(false); } 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, Color.white); return(true); }