Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by unityplease · Feb 12, 2015 at 03:28 PM · uilayoutscrollalignment

Get a scrollRect to begin with the top of content aligned to top of scrollrect pane.

I created a scrollRect for a menu full of buttons.

The number of buttons dynamically changes based on which one is pressed.

There could be as few as 3 buttons or as many at 20.

When there are a greater number of buttons than will fit withing the scrollrect pane mask they can be scrolled by dragging the mouse up and down on the pane.

The buttonpane containing the buttons has a layout element and a grid layout script attached.

The parent content pane has a content size fitter script AND a layout element script and a vertical layout group attached.

The parent of the content pane gameobject is a gameobject that has a scrollrect attached and an image and a mask.

The parent of the scrollrect gameobject is the canvas and has an image attached.

The size of the buttonpane stretches vertically when more buttons are added (when the menu changes).

How to I get the content pane top bound to be aligned with the scrollrect objects top bound whenever the content pane's number of buttons changes?

I could add a code example but because the whole structure was created and initialized in code and the number of buttons within the grid layout group are enabled/disabled by a lot of other code it would probably be more of a hindrance than a help as it numbers over 500 lines.

The problem is I do not know how many buttons will be in the menu at any one time the contentpane size is driven automatically by the number of buttons currently enabled in the buttonpane child object.

I'm looking for some kind of function that will align the top of one rect transform to the top of another rect tranform in c#.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
8

Answer by chrissung · Feb 16, 2015 at 11:24 PM

If the goal is to have the buttons fill in from the top, this can be achieved by setting the anchor and pivot of the content pane to be the top of parent gameobject that has the scrollrect. The live training video shows how this is done:

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/creating-scroll-lists-at-run-time

and the Hints section of the scrollrect manual page references this as well:

http://docs.unity3d.com/Manual/script-ScrollRect.html

In the video, because the content pane is stretched in both directions to start, the default behavior is to fill in from the middle, since this is where the pivot is. If you change its y anchors to be ymin: 1; ymax; 1 and the pivot to y: 1, the buttons within the scrollrect will fill in from the top. You can see the tutor actually make this change in the video.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Content size fitter alignment issue 1 Answer

Unity5 new UI render problem on Android 1 Answer

Vertical Layout Group, how to set different child aligments 2 Answers

Infinite Scroll Rect? 0 Answers

How to Make Smooth Scroll Feature using GUI ScrollTo 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges