Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Need help explaining things from the Unity Manual in regards to UI.

Discussion in 'UGUI & TextMesh Pro' started by asperatology, Oct 20, 2015.

  1. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Taken from this manual article here:

    What does it mean by "stretching behavior"? Is it when the UI element is filling up the parent UI element, creating skewed pictures, images, texts, buttons, and other UI elements? Or it is stretched because of calculating position vectors because the coordinate system uses normalized values (0 through 1)?

    Where can I get the anchors' positions, when "anchoredPosition determines the position of the pivot?

    Are you allowed to put negative values in, so when the rect is stretched, the rect transform moves in the opposite direction?

    And as the last question mentioned, how do I determine the anchors' position?

    Thanks.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    The positions are relative to the pivot point. So if they are spread, this means it the graphic area of the RectTransform is stretched to meet the bounds. You can see an example of this if you have an Image and alter the values.

    The anchored position is the objects fixed position in world space, this is relative to the pivot point for the GO

    You can, but if those values cause the UI object to be come reversed, it won't draw and you will see a red rectangle in the scene view.

    This depends on what you mean, the position is usually the pivot. The anchors then control the drawable / position of the RectTransform relative to the pivot. Whether a pivot is fixed to a position, or whether it grows / shrinks based on the dimensions of it's parent.

    Most of the above you can see clearly by just playing with the Anchors, or watching the UI learn videos demonstrating it (or any books you might find ;D)
     
    jcredible likes this.
  3. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Hi,

    Thanks for answering but I still don't understand.

    How would I get the anchors' position from the anchoredPosition variable? I plan to code the UI elements up rather than visually placing them, and I want to learn about setting the anchor positions (not the pivots, but the actual anchors).

    Depending on the dimensions of the game object, would it be possible to have the pivot points be scripted to move at an offset?

    Thanks.
     
  4. jcredible

    jcredible

    Joined:
    Dec 4, 2012
    Posts:
    24
    The anchors can be set individually. I believe there's an AnchorMin and an AnchorMax which are both a Vector2d that contain a x and a y value. They take a float of 0 to 1 value where the range is a percent of the whole ui component. Yes, you can use a script to increment them at an offset. I'm doing that for one of my scripts.

    I've never messed with the pivot programmatically but someone else may be able to answer that.
     
  5. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Thanks for the info.

    I'll wait.
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
  7. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Thank you.