// Organizes all the sprites in a single texture nicely on a 2D "table" based on their original texture position // Only call this with spritesheet with all Sprites equal size public static Dictionary <Vector2Int, TileDragAndDropHoverData> CreateHoverData(Texture2D sheet, GridLayout.CellLayout cellLayout) { Dictionary <Vector2Int, TileDragAndDropHoverData> result = new Dictionary <Vector2Int, TileDragAndDropHoverData>(); List <Sprite> sprites = GetSpritesFromTexture(sheet); Vector2Int cellPixelSize = EstimateGridPixelSize(sprites); // Get Offset Vector2Int offsetSize = EstimateGridOffsetSize(sprites); // Get Padding Vector2Int paddingSize = EstimateGridPaddingSize(sprites, cellPixelSize, offsetSize); if ((cellLayout == GridLayout.CellLayout.Isometric || cellLayout == GridLayout.CellLayout.IsometricZAsY) && (HasSpriteRectOverlaps(sprites))) { foreach (Sprite sprite in sprites) { GetIsometricGridPosition(sprite, cellPixelSize, offsetSize, out Vector2Int position); result[position] = new TileDragAndDropHoverData(sprite, Vector3.zero, (Vector2)cellPixelSize / sprite.pixelsPerUnit, false); } } else { foreach (Sprite sprite in sprites) { GetGridPosition(sprite, cellPixelSize, offsetSize, paddingSize, out Vector2Int position, out Vector3 offset); result[position] = new TileDragAndDropHoverData(sprite, offset, (Vector2)cellPixelSize / sprite.pixelsPerUnit); } } return(result); }
// Organizes all the sprites in a single texture nicely on a 2D "table" based on their original texture position // Only call this with spritesheet with all Sprites equal size public static Dictionary <Vector2Int, TileDragAndDropHoverData> CreateHoverData(Texture2D sheet) { Dictionary <Vector2Int, TileDragAndDropHoverData> result = new Dictionary <Vector2Int, TileDragAndDropHoverData>(); List <Sprite> sprites = GetSpritesFromTexture(sheet); Vector2Int cellPixelSize = EstimateGridPixelSize(sprites); // Get Offset Vector2Int offsetSize = EstimateGridOffsetSize(sprites); // Get Padding Vector2Int paddingSize = EstimateGridPaddingSize(sprites, cellPixelSize, offsetSize); foreach (Sprite sprite in sprites) { GetGridPosition(sprite, cellPixelSize, offsetSize, paddingSize, out Vector2Int position, out Vector3 offset); result[position] = new TileDragAndDropHoverData(sprite, offset, (Vector2)cellPixelSize / sprite.pixelsPerUnit); } return(result); }