- Home /
Alternative to GUI Scrollview ?
Hi guys,
I want to know if there is any other choices to create a scroll view aside from GUI Scrollview. The problem with GUI elements was that they displayed differently coordinates and size-wise between Unity and actual devices, which made my development process difficult. So, any suggestions ? Thanks a lot in advance !
Answer by YoungDeveloper · Apr 25, 2014 at 08:27 AM
Hi, you can create a GUI group, render everything inside it, and when "scrolling" just move GUI group y. What comes to screen independence, it's tricky, mostly you should use percentage instead of actual pixels, because or retina screens. You could use matrix, but its tends to stretch things..
//Button which is 10% from horizontal sides
private int screenXp;
private Rect rect_button;
private void Start(){
screenXp = Screen.width/100;
rect_button = new Rect(screenXp * 10,
0,
Screen.width - screenXp * 20,
Screen.height);
}
private void OnGUI(){
GUI.Button(rect_button, ""); //same button on all devices, by not considering the ratio
}
Thank you for the answer ! What if just like the GUI scroll view, I want the scroll area to be just a small section within the screen, how could that be achieved using your method ? And what do you mean by "GUI group" ?
Hi, if you want invisible wall effect, when scroll content "hides" after certain point, you will have to use scrollview. For gui group https://docs.unity3d.com/Documentation/ScriptReference/GUI.BeginGroup.html Everything inside group will be binded to its coordinate system.
Thank you ! Even though there's still some problems not resolved yet, now I have more choices to consider.
Actually the ScrollView follows some strict rules and actually just pushed a GUIClip to the stack and passes the offset parameters. A GUI-Group does the same thing but you can't specify a client area offset. With two GUI-groups you can simulate what the ScrollView does. I've made auch a CustomScrollview some years ago for another UA question. This was only to completely hide the scrollbars and just provide scrolling without visible handle(s).
Your answer
Follow this Question
Related Questions
Problem with modifying scrollPosition on android 1 Answer
GUI Scroll View 1 Answer
Is there a way to scroll GUI text WITHOUT scrollbars? 2 Answers
GUI Follow Object On-Screen 1 Answer
How to disable ScrollView dragging 4 Answers