Advertisement
Guest User

Untitled

a guest
Dec 8th, 2024
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. // Button style
  2. GUIStyle toggleStyle = new GUIStyle("Button");
  3. toggleStyle.fixedWidth = buttonSize;
  4. toggleStyle.fixedHeight = buttonSize;
  5. toggleStyle.fontSize = 8;
  6.  
  7. // Grid layout
  8. private void DrawGuiContentGrid(string label, IEnumerable<GridButton> gridButtons, GUIStyle toggleStyle)
  9. {
  10. GUILayout.Label(label, EditorStyles.boldLabel);
  11.  
  12. if (gridButtons == null || gridButtons.Count() == 0)
  13. {
  14. GUILayout.Label("No objects found");
  15. }
  16. else
  17. {
  18. const int padding = 40;
  19. int columns = Mathf.Max(1, Mathf.FloorToInt((EditorGUIUtility.currentViewWidth - padding) / buttonSize));
  20. int c = 0;
  21. GUILayout.BeginHorizontal();
  22. int i = 0;
  23. foreach (GridButton gridButton in gridButtons)
  24. {
  25. if (gridButton.Content == null)
  26. {
  27. continue;
  28. }
  29.  
  30. bool wasSelected = gridButton == selectedGridButton;
  31. bool selected = GUILayout.Toggle(gridButton == selectedGridButton, gridButton.Content, toggleStyle);
  32. if (selected && !wasSelected)
  33. {
  34. gridButton.OnClick();
  35. }
  36. i++;
  37. c++;
  38.  
  39. if (c >= columns)
  40. {
  41. GUILayout.EndHorizontal();
  42. GUILayout.BeginHorizontal();
  43. c = 0;
  44. }
  45. }
  46. GUILayout.EndHorizontal();
  47. }
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement