Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Button style
- GUIStyle toggleStyle = new GUIStyle("Button");
- toggleStyle.fixedWidth = buttonSize;
- toggleStyle.fixedHeight = buttonSize;
- toggleStyle.fontSize = 8;
- // Grid layout
- private void DrawGuiContentGrid(string label, IEnumerable<GridButton> gridButtons, GUIStyle toggleStyle)
- {
- GUILayout.Label(label, EditorStyles.boldLabel);
- if (gridButtons == null || gridButtons.Count() == 0)
- {
- GUILayout.Label("No objects found");
- }
- else
- {
- const int padding = 40;
- int columns = Mathf.Max(1, Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - padding) / buttonSize));
- int c = 0;
- GUILayout.BeginHorizontal();
- int i = 0;
- foreach (GridButton gridButton in gridButtons)
- {
- if (gridButton.Content == null)
- {
- continue;
- }
- bool wasSelected = gridButton == selectedGridButton;
- bool selected = GUILayout.Toggle(gridButton == selectedGridButton, gridButton.Content, toggleStyle);
- if (selected && !wasSelected)
- {
- gridButton.OnClick();
- }
- i++;
- c++;
- if (c >= columns)
- {
- GUILayout.EndHorizontal();
- GUILayout.BeginHorizontal();
- c = 0;
- }
- }
- GUILayout.EndHorizontal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement