Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Chat window ScrollView that follows the chat.

Discussion in 'Immediate Mode GUI (IMGUI)' started by Yarry, Apr 27, 2011.

  1. Yarry

    Yarry

    Joined:
    Mar 10, 2010
    Posts:
    9
    Hi guys,

    So after messing with creating a small chat, I've come up with what I suspected to be a fairly simple problem, alas I have not been able to solve it after a while of searching around.

    Basically I have a chat that is constantly updated with new lines of text. However, when my chatwindow exceeds downwards I would like my scroll-bar to follow, so that it always focuses on the newest thing that has been written (the buttom of the scrollview) rather than the oldest thing in the chat (the top of the scroll view).

    The chat-window is here:
    Code (csharp):
    1.  
    2. public Vector2 scrollPosition = Vector2.zero;
    3.  
    4. GUILayout.BeginScrollView(new Rect(10, 300, 100, 100), scrollPosition, new Rect(0, 0, 220, 200)););                
    5. GUILayout.TextArea(this.ChatClient.ChatLines.ToString(), GUILayout.ExpandHeight(true));
    6. GUILayout.EndScrollView();
    7.  this.InputLine = GUILayout.TextField(this.InputLine);
    8. GUILayout.EndArea();
    9.  
    How would I go on about making the chat expand upwards rather than downwards, or have the scrollview bind to the bottom rather than the top of the window?

    Thanks for any help,
    Yarry
    (I hope I'm making myself clear)
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    bind to bottom is easy, just force the position of the scrollview down to an eternally large amount :)

    the chat example available, the chat in the networking example in the resources or the chat code on the unifycommunity show that in action :)
     
  3. Yarry

    Yarry

    Joined:
    Mar 10, 2010
    Posts:
    9
    I'll check it out, thanks!
     
  4. Yarry

    Yarry

    Joined:
    Mar 10, 2010
    Posts:
    9
    Quite easy indeed :p

    scrollPosition.y = 10000;