In my inventory system, an item could take more than one slot, 2x2, 2x3, 3x3, etc.
Each item has a texture - I don’t care about the texture size (for a 2x2 item, the texture size doesn’t have to be like, 256x256 or 128x128, but it would be better if it was)
Since I’m using NGUI, the item slot is actually a button, with a background, an icon (both sprites) and a label. I instantiate the slots, by using a Slot prefab, which has a script that stores the Slot size, for now I’m using 50. There’s also a spaceBetweenSlots variable, which is 5.
So if I had a 2x2 item, its background would be of size 105x105, I scale the background to that size.
But the problem is, the item icon. I can’t seem to know how to scale the icon, for it to fit perfectly inside the background. Take a look at this example:
Now the RedHerb fits, because its size is 594x601 and I’m scaling it by 100x100x1, but the gun is 640x453, if I scale it by the same scale as the Herb, you would get the results above.
Now the question is, how can I scale the icon to perfectly sit inside the background?
I came up with an idea of finding the difference between the icon’s and the background’s size, I keep scaling down the icon till there’s a low dif between the two sizes. But NGUI is giving me a hard time of doing anything -_-
For my idea to work I just need the icon’s and the background’s size. I searched and found NGUIMath.CalculateAbsoluteWidgetsBounds, I’m not sure how to use it, it asks for a transform, and returns a Bounds, so I gave my background’s, it got me back a bound with size of 0.2x0.2, did the same for the icon it gave me back a size of 0.0x0.0 lol O_O what is that?!
I tried background.relativeSize, I got back a V3 of (50,50,1) - NGUI forums says to Scale that by background.cachedTransform.relativeSize, to get the size in pixles, so I did:
Is that correct? is that how to scale two vectors? - I got back a V2 of (1.0, 1.0)
Any help would be much appreciated, thanks a lot.