Search Unity

I do not really understand how the anchor system works

Discussion in 'UGUI & TextMesh Pro' started by bali33, Aug 22, 2014.

  1. bali33

    bali33

    Joined:
    Aug 14, 2011
    Posts:
    232
    Hi,

    I have watched the video about the new UI system but I'm still confused about the new anchor system. How the UI element will behave according to the 4 anchors it's not quite clear. Depending if the four anchors are grouped or not the behavior seems to not be the same. Is there somewhere in the documentation a clear explanation about that tool ?

    Thank you
     
    Acoustic125 likes this.
  2. Zaladur

    Zaladur

    Joined:
    Oct 20, 2012
    Posts:
    392
  3. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Anchors provide a great way of utilizing both relative and absolute coordinates, all at once. The anchors themselves are in relative space, meaning they have a value between 0 (left or bottom) and 1 (right or top). In addition, the elements have an absolute offset to their anchors. This way, you could easily do something like "place this button at 50% of the screen width, minus 20 pixels".

    In short, it boils down to this:

    If the anchors are all combined into a single point the UI element will simply render at a fixed, absolute size (offset to the anchors), at a relative position as marked by the anchors.

    If the anchors are split the button will scale along in whatever direction they're split. Remember, anchors are relative. This means once they're split into, say, [0.2, 0.5] and [0.3, 0.5], the anchors will always have (0.3 - 0.2 = ) 0.1 times the screen width between them. If you place the anchors at the element's sides, this means the element will also always have 0.1 screen width between them.

    Hope this helped a bit! =)
     
    mustafahtp3, skabed, Roger-W and 10 others like this.