- Home /
How to have both, a scroll view AND vertical Layout?
I am trying to make a chat box, haven't really had much help... Only thing that was recommended was to use a vertical layout group. However, I used that and now my scroll view doesn't work. I just need help getting a chatbox working with UnityUI. I can handle the network side. I have a Panel_Chatbox, with a mask and scrollRect. I have a prefab "messageObject" consisting of a Panel, Image, and Text. Think of facebook's messenger. It's going to be similar to that, a box containing the content, a user avatar, and the text. So when the user types in the input field and hits send, that text will be the "messageToSend" of the instantiated messageObject, their avatar will be the Image, and so on. So at this point, when I hit send, the messages stack ontop of each other. I need them to remain the same width and height, but go up the parent panel, as more messageObject's come in. Then the user can use the scroll view to go up and read previous messages. I've reached out on this several times cause I am completely stuck, but not really any responses, or someone telling me how to visually design the chat box. I just need to get it to work properly. I tried the vertical layout group angle but that fails as the content autoscales to the panel depending on the amount of messageObjects eventually getting tiny, and they don't move up the list.. I tried playing around with settings but no luck. I would just greatly appreciate someone helping me though creating this part
can you upload a picture or something of what you chat box to look like and what it looks like now?
Answer by Mmmpies · Jan 23, 2015 at 02:05 PM
Try this, it's based on a @BoredMormon tutorial but just fills a scroll panel with a load of rubbish text, should get you most of the way there.
Links to the tutorial are in the document.
EDIT:
Looking at that video you've deffinately got your pivot point in the wrong place as that's exactly what happens when you leave the pivot in the center. If you got through that document and the related Richard Gubb tutorial it show you how to move the pivot. I suspect to force it to show the bottom one you'll need to set that VerticalNormalizedPosition like I said.
I'll be able to check when I get to a PC with Unity though, should be in a couple of hours.
Nice design BTW.
EDIT 2:
OK the content of the button probably need a content size filter rather than a fixed size with, set the mimimum size and also add a contentSizeFilter to expand should the text increase. You probably want to switch off the best fit part of the text for that to work and just stick with a font size of your choice.
Difficult to work out without Unity around to cheeck the values but we'll get it sorted don't worry.
EDIT 3
OK on the scroll panel where I assume you now have the pivot at the bottom change the Content Size Filter to Vertical Fit = Preferred Size. That works for my simple text display but you may need additional scripts on you panel as it's more complex.
well i have it pretty much finished, the only issues is they are auto scaling as more messages come in to the chatbox, shrinking in size
I need the scroll view to automaticly be at the bottom when new text is entered, cause right now its staying center and after you type you have to scroll down to see it.
$$anonymous$$ake it to where the user can type out a paragraph rather than just a few characters...
$$anonymous$$ake it to where the Panel size will scale larger to fit the users text inside of it.
Fix the issue where if I type more than lets say 5 words, the input field will let me, but when i hit send, it only sends the last 5 words that are currently showing in the input field... the rest doesn't send
But regardless of the searching I can't find the answers
You could do the opposite of what the document says and set the pivot of the parent panel to the bottom but I don't have Unity available to me at the moment so I'm not sure if that will add the new messages above it.
Other than that try setting the VerticalNormalizedPosition of the scrollRect to 0, but hey that's from memory so may not be the right way round.
Just create a public ScrollRect $$anonymous$$yScrollRect to access that VerticalNormalizedPosition value.
Sorry for any typos, like I said no access to Unity AT$$anonymous$$.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
Name/Screen Name Input 0 Answers
ExpManagement problems 1 Answer