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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

GUILayout.BeginScrollView - get maximum scrollPosition.y value?

Discussion in 'Immediate Mode GUI (IMGUI)' started by Rukenshia, Apr 26, 2014.

  1. Rukenshia

    Rukenshia

    Joined:
    Jan 2, 2014
    Posts:
    1
    Hello,

    Im struggling to retrieve the maximum value the scroll position of GUILayout.BeginScrollView on the y axis.
    Inside the ScrollViews, there are labels (its going to be a chat).

    Each Label comes with a GUILayout.Space(-8) after it.

    Since the GUI is not static but the rects are created according to the screen resolution, I can't just put some fixed formula to get the maximum scroll position (tried that, of course it went wrong when changing resolution).

    So what I have tried is to add all the label heights together, but the result is not correct.

    Code (csharp):
    1. ytotal += GUI.skin.label.CalcSize(new GUIContent(msg.Message)).y - 8f;
    is what I used to calculate it. In my tests, it always gave me 338 but when i scrolled down on different resolutions, the scrollPosition.y value differed from that.

    How can I solve that problem?
     
  2. aanimation

    aanimation

    Joined:
    Oct 23, 2012
    Posts:
    49
    watching