Hi I’m trying to add scroll bars to my editor window so I can effectively look around a graph I’ll be making. Here I’ve made a comically large button to represent the graph. I am unable to use the scroll bars to scroll along the length of the button despite the fact that the Area Rect and button is too large to view, what am I doing wrong?
Thanks for any help.
public class DemoWindow: EditorWindow{
Vector2 scrollPos = Vector2.zero;
void OnGUI(){
scrollPos = EditorGUILayout.BeginScrollView(scrollPos, true, true, GUILayout.Width(window.position.width), GUILayout.Height(window.position.height));
GUILayout.BeginArea(new Rect(0, 0, 1500, 1500));
GUILayout.Button("Test", GUILayout.Width(1500));
GUILayout.EndArea();
EditorGUILayout.EndScrollView();
}
}
1 Like
The problem seems to be with having a GUILayout Area with in the scroll view, without the GUI Area then the scroll bars will function correctly.
using UnityEngine;
using System.Collections;
public class TestScrollView : MonoBehaviour {
Vector2 scrollPosition = Vector2.zero;
void OnGUI(){
scrollPosition = GUILayout.BeginScrollView(scrollPosition, true, true, GUILayout.Width(100), GUILayout.Height(100));
//GUILayout.BeginArea(new Rect(0, 0, 300, 300)); //Does not display correctly if this is not commented out!
GUILayout.Button("I am a button", GUILayout.MinWidth(150), GUILayout.MinHeight(150));
//GUILayout.EndArea();
GUILayout.EndScrollView();
}
}
4 Likes
If you want the scrollbar to set automatically according to items in your EditorWindow do this
Vector2 scrollPosition = Vector2.zero;
private void OnGUI()
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true);
//Your Functions…
GUILayout.EndScrollView();
}
1 Like