im creating a drop down menu, where when a button is pressed, a window pops up containing buttons…each button corresponds to an item in a list. the problem is the method that calls the window function is static, and cant contain any variables for gui style etc. how can I pass those type of parameters to the window creating method.
You can pass GUIStyle as 5-th parameter in GUI.Window() function.
You can pass them with a static variable, that is then visible from outside of the window function.
I tried that, but I want to be able to reuse the dropdown menu several times with different content, the way a normal gui control like a button is used… static variables only hold one value across all of the components so I end up with several lists all with the same thing.
yeah but how would I pass a gui style for the buttons that are on the window
Each window function get a WindowId parameter (it’s first paramater), you can use like a key to take a style from presaved collection (like Dictionary<int, GUIStyle> as in code bellow).
Dictionary<int, GUIStyle> styles = new Dictionary<int, GUIStyle>();
void OnGUI()
{
styles.Add(1, new GUIStyle());
GUI.Window(1, DoMyWindow, "Window 1");
}
void DoMyWindow(int windowId)
{
GUI.Button(new Rect(0,0, 100, 30), "button", styles[windowId]);
}
A lambda expression should work just fine here.
void OnGUI()
{
GUIStyle style = new GUIStyle();
Rect rect = new Rect();
GUI.Window(1, rect, (int id) => { WindowContent(style); }, "Window");
}
void WindowContent(GUIStyle style)
{
//...
}
Thabnks for necroing this - it worked