SelectionGrid.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 SetItems(string[] items, int selectedIndex = 0)
  26. {
  27. this.Items = items;
  28. this.SelectedItem = selectedIndex;
  29. }
  30. public void Draw(GUIStyle gridStyle, params GUILayoutOption[] layoutOptions)
  31. {
  32. if (!Visible) return;
  33. GUILayout.BeginHorizontal();
  34. int selected;
  35. selected = GUILayout.SelectionGrid(SelectedItem, Items, XCount, gridStyle, layoutOptions);
  36. GUILayout.EndHorizontal();
  37. if (selected != SelectedItem) SelectedItem = selected;
  38. }
  39. public override void Draw(params GUILayoutOption[] layoutOptions)
  40. {
  41. this.Draw(new GUIStyle(GUI.skin.button));
  42. }
  43. }
  44. }