I have a UI Element that can be Zoom In & Out (This feature works by modifying Its sizeDelta) and You can create Pins but when you Zoom In/Out the Pins you’ve created keep their positions so they not longer represent what you original intended (They are already a child of this UI Element, hence the wording of the question but RectTransform don’t work like regular Transforms, please don’t answer by saying “Make it a child”)
I’m having a hard time solving this as It easy as It may seem. Any help it will be greatly appreciated. I need to do this via code.
When a pin is first placed (in this case I’ve put this in the Start method), the code determines where the pin is positioned as a percentage relative to the bounds of the parent rect at its current size. This results in an X and Y coordinate that sits between 0 and 1 (similar to what UV coordinates are for a texture map basically).
In Update, these percentage values are then used to get back the correct X and Y position of the pin by lerping them against the new size of the parent rect.