Page 1 of 1

Scrolling behaviour with Circular example

Posted: Tue Jun 14, 2022 10:39 am
by tamaracktoo
Hey,

Noticed some odd scrolling behaviour with the subsurface circular example that I couldn't quite figure out tracing through the code. Wondering if it might just be the native behaviour in unity's scrollview.

If you have text that has already scrolled, and options appear, after you select an option and the options disappear from the window, it scrolls back up (moving the last line to the very bottom of the viewport) and then proceeds to scroll as it adds lines. It's sort of jarring visually when trying to read the text and if you have a long list of options quite distracting.

I am guessing it's because when the gameobjects for the options are removed the scrollview readjusts to show the maximum amount of content possible. I am wondering if there's a way to override this so that it didn't readjust, so that when the option disappear, it stays put, and then continues rendering from the last content piece. I looked through the code and played a bit with the ScrollToBottom() placements but that didn't seem to have any impact.

Realize it might be just the way Unity's scrollview works though. Thanks for any assistance.

Re: Scrolling behaviour with Circular example

Posted: Tue Jun 14, 2022 11:42 am
by Tony Li
Hi,

Yes, it's kind of the way the scrollview works. When the response menu disappears from the scroll content, it adjusts to fit the new, shorter height. Feel free to change the code. It's just a little example, not part of the core Dialogue System asset. Off the top of my head, you could add a Layout Element to the Content GameObject. After showing the menu (e.g., in the TemplatedConversationLogUI's ShowResponses method), you could set the Layout Element's Min Height to be the current height. Example (untested):

Code: Select all

public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
{
    base.ShowResponses(subtitle, responses, timeout);
    if (autoScrollResponseMenu) ScrollToBottom();
    
    // Add lines similar to this:
    Canvas.ForceUpdateCanvases();
    contentLayoutElement.minHeight = contentPanel.rect.height; // Assumes you have a variable contentLayoutElement.
}
This way the scroll content height only grows; it never shrinks by turning off the response menu.

Re: Scrolling behaviour with Circular example

Posted: Tue Jun 14, 2022 11:48 am
by tamaracktoo
Awesome -- that makes sense. I was trying to figure out the right spot to "intercept" things -- that is a great solution. I will give it a try (and report back). Thanks for the quick reply!

Re: Scrolling behaviour with Circular example

Posted: Tue Jun 14, 2022 2:38 pm
by tamaracktoo
Confirmed. This worked! Thanks! That helped me understand how things are connected under the hood better as well.

Re: Scrolling behaviour with Circular example

Posted: Tue Jun 14, 2022 3:00 pm
by Tony Li
Great! Thanks for confirming. Glad I could help.