SelectionGrid.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class SelectionGrid : BaseControl
  6. {
  7. public string[] Items { get; set; }
  8. public int XCount { get; set; }
  9. private int selectedItem;
  10. public int SelectedItem
  11. {
  12. get => selectedItem;
  13. set
  14. {
  15. this.selectedItem = value;
  16. OnControlEvent(EventArgs.Empty);
  17. }
  18. }
  19. public SelectionGrid(string[] items, int xCount, int selectedTab = 0)
  20. {
  21. Items = items;
  22. XCount = xCount;
  23. this.selectedItem = selectedTab;
  24. }
  25. public void Draw(GUIStyle gridStyle, params GUILayoutOption[] layoutOptions)
  26. {
  27. if (!Visible) return;
  28. GUILayout.BeginHorizontal();
  29. int selected;
  30. selected = GUILayout.SelectionGrid(SelectedItem, Items, XCount, gridStyle, layoutOptions);
  31. GUILayout.EndHorizontal();
  32. if (selected != SelectedItem) SelectedItem = selected;
  33. }
  34. public override void Draw(params GUILayoutOption[] layoutOptions)
  35. {
  36. this.Draw(new GUIStyle(GUI.skin.button));
  37. }
  38. }
  39. }