- Home /
EditorWindow: Scrollview
Hi,
I'm trying to create a custom editor window but i'm having some problems. My width and height scroll bar has a small wiggle room between values (even if there is no content) needed to extend to them.
Also, when there is too much content and I actually need it to scroll. It stays the same.
Thanks in advance!
an image of what I mean, and here's the script:
Vector2 scrollPos;
void OnGUI () {
scrollPos = EditorGUILayout.BeginScrollView (scrollPos,
true,
false,
GUILayout.Width(Screen.width ),
GUILayout.Height(Screen.height - 20));
int posx = 20;
for (int i = 0; i < asm.mylist.Length; i++) {
GUILayout.BeginArea(new Rect(posx, 20, 60, Screen.height - 80 ));
asm.mylist [i].volume = GUILayout.VerticalSlider(asm.mylist [i].volume, 0, 1);
EditorGUILayout.LabelField (asm.mylist [i].gameObject.name);
GUILayout.EndArea();
posx += 70;
}
EditorGUILayout.EndScrollView();
}
Answer by slavo · Oct 03, 2014 at 12:28 PM
You are doing lot of hand computing that is wrong in some way. But I was unable to find what exactly is wrong. But you can rewrite your script to let unity handle all sizes for you automaticlly.
Yuor script would look like
Vector2 scrollPos;
void OnGUI () {
scrollPos = EditorGUILayout.BeginScrollView (scrollPos,
false,
false);
//vertical space
GUILayout.Space(20);
GUILayout.BeginHorizontal();
for (int i = 0; i < asm.mylist.Length; i++) {
//in horizontal layout this is horizontal space
GUILayout.Space(20);
//Eqivalent of Begin area, but you only care about width, rest is automaticlly compute, so you do not need "posx"
GUILayout.BeginVertical(GUILayout.Width(70));
asm.mylist [i].volume = GUILayout.VerticalSlider(asm.mylist [i].volume, 0, 1);
EditorGUILayout.LabelField (asm.mylist [i].gameObject.name);
GUILayout.EndVertical();
}
GUILayout.EndHorizontal();
EditorGUILayout.EndScrollView();
}
Thanks for the reply worked a charm!
Looks like i'll just have to use more automatic adjustments from now on! I seem to get lost in hardcoded values