public AtlasRegion Pack(string path) { var tex = Load<Texture2D>(path, false); if (tex == null) { Debug.LogWarningFormat("[Packer] {0} not found", path); return null; } if (tex.width > width || tex.height > height) { Debug.LogError("[Packer] A texture size is bigger than the sprite sheet size!"); return null; } var region = PackRegion(new Vector2Int(tex.width, tex.height)); if (region == null) return null; region.name = path; region.page = this; region.degrees = 0; region.rotate = false; region.width = region.originalWidth = tex.width; region.height = region.originalHeight = tex.height; _packedSprites.Add(path, region); CopyTex2RT(tex, region); region.u = (region.x + 1) / (float)width; region.v = (region.y - 1 + tex.height) / (float)height; region.u2 = (region.x - 1 + tex.width) / (float)width; region.v2 = (region.y + 1) / (float)height; region.ReferenceCount++; return region; }
private AtlasRegion PackRegion(Vector2Int v2I) { var v2Ix = v2I.x; var v2Iy = v2I.y; var index = GetFreeAreaIndex(v2Ix, v2Iy); if (index < 0) return null; var freeArea = _mFreeAreas[index]; var target = AllocateRectangle(freeArea.x, freeArea.y, v2Ix, v2Iy); // Generate the new free areas, these are p