I want to implement an image gallery with Unity (2D). I have a Canvas
logically divided into squares of, say, 100x100 units. Then:
- each "square" is populated by an image downloaded dynamically from the internet (using the www class);
- the image is not necessarily square: in this case, I want to "scale and crop the image": the aspect ratio is preserved and the image fills the whole square;
- when a user clicks on a square, the image expands to its natural size on the middle of the screen. Another click an the image goes back to the square size/position;
- at a regular interval, a square is taken randomly and its image is replaced by a new one.
I am new to Unity and I already tried a lot of different approaches. My real problem is for the scale and crop. Indeed:
- the
Gui.DrawTexture()
takes an argumentscaleMode.ScaleAndCrop
, which is exactly what I need. But this is part of the old UI system... - the new UI offers
Image
andRawImage
Gui components, but out of the box we can either keep aspect ratio or fill the square, not both. - I tried to create a "texture thumbnail" by copying a square of pixels into a new texture. It works, but animations between thumbnail and fullsize image are not possible anymore...
I am sure there is a way to use the new UI functionalities and get the scale and crop effect, but I can't figure out how. Would someone have an advice for me ?