private static void sortTexture() { // for (int i = 0; i < _images.Count; i++) foreach (var item in _images) { Bitmap image = item.Value; TextureBlock block = new TextureBlock(); block.width = image.Width; block.height = image.Height; block.name = item.Key; _blocks.Add(block); } _blocks.Sort((TextureBlock a, TextureBlock b) => { return(a.width * a.height > b.width * a.height ? -1 : 1); }); }
public static void package() { for (int i = 0; i < _blocks.Count; i++) { TextureBlock block = _blocks[i]; for (int j = 0; j < _vectors.Count; j++) { Position position = _vectors[j]; if (!suitableBlocks(position, block.width, block.height)) { continue; } drawTexture(position.x, position.y, block.name); Console.WriteLine(block.name); // BitmapHelper.SaveImage(string.Format("{0}/{1}.png", @"G:\Resources", "Texture"), _texture); // 修改新的节点 removeVector(position.x, position.y); int newX = position.x + block.width; int newY = position.y + block.height; // 检查右上角 if (newX < _texture.Width && position.y < _texture.Height) { removeInvalidVector(newX, position.y, block.width, block.height); pushVector(newX, position.y); } // 检查左下角 if (position.x < _texture.Width && newY < _texture.Height) { removeInvalidVector(position.x, newY, block.width, block.height); pushVector(position.x, newY); } // 检查右下角 if (newX < _texture.Width && newY < _texture.Height) { removeInvalidVector(newX, newY, block.width, block.height); pushVector(newX, newY); } break; } } }