Auto-resizing response panel to number of responses

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Auto-resizing response panel to number of responses

Post by Hyrad »

Hello again, I am trying to figure out the best way of doing this, since I am offering three possible answers to the player and the panel in default state is about twice the size. Is it possible to affect the size of the panel as well?

Thanks for the info,
- Jeff
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto-resizing response panel to number of responses

Post by Tony Li »

Hi Jeff,

Yes. I'll assume you're using Unity UI, which is what the generic dialogue UI in the Dialogue Manager prefab uses. Add a Content Size Fitter. You may need to play around with it a bit and read over the Unity UI Auto Layout section of the Unity manual.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Auto-resizing response panel to number of responses

Post by Hyrad »

Ok thanks for the pointers Tony. I will check it out!
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto-resizing response panel to number of responses

Post by Tony Li »

I'll confess that it always takes me a bit of fiddling with Unity UI to get auto-sizing to work right. But it's standard Unity UI stuff, not specific to the Dialogue System. If you get stuck, let me know and I'll try to work out the exact steps.
Hyrad
Posts: 26
Joined: Fri Jan 13, 2017 5:11 pm

Re: Auto-resizing response panel to number of responses

Post by Hyrad »

Thanks for that, I've tried to fiddle with it with mixed results but I will research further into it. Will let you know if I come up with a quick recipe for other forum users ;)
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Auto-resizing response panel to number of responses

Post by Tony Li »

If you get stuck or are curious to see another approach, here's how I just set it up:

Download Example Scene: AutosizeResponsePanel_2017-01-18.unitypackage

First, I got rid of the scroll rect and scroll bar, and made the Response Button Template a direct child of the Response Panel:

Image

Then I added a Content Size Fitter to the Response Panel and set Vertical Fit to Preferred Size, which shrinks it down to fit its contents vertically:

Image

(I also changed the response panel's background color to an ugly yellow to make it easy to see.)

The end result looks like this:

Image
Post Reply