Some issues with the setting of the scroll bar inside Unity

Source: Internet
Author: User

Unity version 2017.2

When using Unity Scroll View to create a feature that automatically adapts to the size of the content and scrolls to the bottom, there is a problem.

First, the content adapts to what I use when a content size Fitter component and sets only the best vertical direction size. Set to scroll view's content object, allowing this to automatically change size according to the size of the sub-object, making it possible to scroll

Then I added a text text at the bottom, with the text of the text Mesh Pro plug-in. In fact, it is similar to Ugui. This text is also set size adaptive

Then I'll add the message to the text component in the code,

At the time of testing, a problem was found that the content size adaptation was always slower than the size of the text component in the bottom, and then in the second time, the first connection was counted in the calculation size.

Baidu, said the problem is the content Size fitter This component will be updated slowly, so it will cause this problem.

The solution is:

Call Layoutrebuilder.forcerebuildlayoutimmediate () This function to pass the content's Recttransform component to the past, to solve the problem of slow size update frame

Layoutrebuilder.forcerebuildlayoutimmediate (Recttransform);

In fact, there are some other ways of saying it, but I did not actually take effect when I tested it in my own project.

Canvas.forceupdatecanvases ();
Update content Adaptive size immediately, test invalid
Container.ContentController.Container.ContentSizeFitter.SetLayoutVertical ();
Container.ContentController.Container.ContentSizeFitter.SetLayoutHorizontal ();

After that, let's scroll to the bottom of the scroll bar each time you add a message:

Scrollrect.verticalnormalizedposition=0

The front is the Scrollrect component on your ScrollView object, then set Verticalnormalizedposition, where 1 represents the top and 0 is the bottom

In fact, you can also set the message up to add, each add in front of the previous sentence, I was added in the back of the previous sentence, so you will need to scroll to the bottom of the function

Some issues with the setting of the scroll bar inside Unity

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.