is there a simple way to get max value of scroll position…i need this to show
additional info if we are able to scroll in the scroll view? and the value is max (user scrolled all the way down) i would hide additional info…
thanks!
is there a simple way to get max value of scroll position…i need this to show
additional info if we are able to scroll in the scroll view? and the value is max (user scrolled all the way down) i would hide additional info…
thanks!
There is a scrollPosition parameter that returns a vector2 of the scrolls current position.
so pseudo code would be
if(GUI.scrollPosition >= 15,0)
{
DisplayInfo()
}
Check out GUIStyle.CalcHeight().
It's a function that calculates the height of a GUI element.
To get the max scroll value you need to subtract the height of the rectangle from the height returned by this function.
We use code like this to determine whether or not we need to detect two finger scroll in a certain window:
maxScroll = Mathf.Round(boxStyle.CalcHeight(theContent, theWidth) - rectHeight);
What the docs say:
A silmilar question here
.If you really talk about GUI.BeginScrollView (/ GUI.EndScrollView) that’s not really difficult. You actually have to provide the size of the viewable area (position-parameter) and the content area size (viewRect-parameter). You can only scroll the difference that doesn’t fit into the viewable area.
A short example:
// C#
Rect viewArea = new Rect(10,10,100,100);
Rect contentArea = new Rect(0,0,150,500);
pos = GUI.BeginScrollView(viewArea, pos, contentArea);
//...
GUI.EndScrollView();
If there where no scrollbars pos.x would be between 0 - 50 and pos.y between 0 - 400. However the scrollbars are displayed inside the viewable area and reduce the size. The default skin for the horizontal / vertical scrollbar takes up 16 pixels. The height is 15 pixels plus 1 pixel top-margin. So in result the useable viewarea is 16 pixels smaller than specified:
original view area: 100, 100
useable view area: 84, 84 // (100 - 16, 100 - 16)
scrollrange-x: [0, 66] // (150 - 84)
scrollrange-y: [0, 416] // (500 - 84)
The GUILayout.BeginScrollView however specifies the required size during layouting. If you “pack” all content inside a group (horizontal or vertical) you can use GUILayoutUtility.GetLastRect to get the size of the whole content area. To get the scroll-range do the same calculations like above.
Alternatively you can setup a custom scrollview like i did here using GUI.BeginGroup
here is the updated link to "[I did here][1]" http://wiki.unity3d.com/index.php/CustomScrollView the old link is pointing to the unifycommunity.com domain that is no longer in use. [1]: http://wiki.unity3d.com/index.php/CustomScrollView
– createdbyx
I don't think it tells you what the projected maximum value is, though.
– syclamothYour right, I'm not aware of any way to find that, other than moving it manually, then printing the scrollPosition and writing it down :). I was hoping, with this information he should be able to produce the functionality he's looking for.
– timskthe problem is that i can do it manually for one resolution, but i think it will change because dimensions are dependent on the Screen.height... is there a way to calculate it somehow? btw thanks for looking into this
– pretenderWell, considering that the scrollposition is a result of all the things you put into the scrollView, you could keep track of the total height of all the objects in the scrollView? Not the most practical of solutions, but I think it should give you the right numbers.
– syclamothi know, but what is the connection between scrollposition and the height of the scrollview? or further between the height of the all elements in the scrollview together?
– pretender