I meant the need to check if values are zero.
I’m building my own scroll box, and pulling the rect.height into the vertical scrollbar.
I guess I’m hacking the GUILayoutUtility to calculate a rect for me, I haven’t come up with a better way yet.
However, my scrollbar goes nuts when I build this, or often doesn’t work at all.
I moved the height calculations into update and check to make sure it’s non-zero. Then it works pretty well, smoothed scrolling (with my scrollbar on the left)
function Update (){
var scrollDif = (Mathf.Round(scrollPosition)- actualScroll);
if(Mathf.Abs(scrollDif) > .01){
actualScroll = (actualScroll + 4*Time.deltaTime*scrollDif);
}
else{
scrollPosition = Mathf.FloorToInt(scrollPosition);
actualScroll = Mathf.Clamp(scrollPosition,0,scrollHeight);//return to int pixel space
}
}
function SomeGUIFunction(id : int){
var test : GUIContent = new GUIContent(tmpJournal);
scrollRect = GUILayoutUtility.GetRect(test, "Copy",GUILayout.Width(390));
scrollHeight = scrollRect.height;
scrollPosition = GUI.VerticalScrollbar(Rect(20,80,10,390),scrollPosition,390.0,0.0,scrollHeight);
var pos = new Vector3(35,80-actualScroll,0);
var q = Quaternion(0,0,0,1);
var s = new Vector3(1,1,1);
var tMatrix : Matrix4x4 = Matrix4x4.TRS(pos, q, s);
GUI.matrix = tMatrix;//scrollbar offset
GUI.BeginGroup(Rect(0,actualScroll,390,392));//clipping
GUI.Label(Rect(0,-actualScroll,390,scrollHeight),tmpJournal, "Copy");
GUI.EndGroup();
pos = Vector3(0,0,0);
tMatrix= Matrix4x4.TRS(pos, q, s);
GUI.matrix = tMatrix;
}
EDIT: After reading your message again, I’ve done this… Thanks for the help.
if (Event.current.type == EventType.Repaint){
scrollHeight = scrollRect.height;
}