TabButton.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using System;
  6. public class TabButton
  7. {
  8. protected GameObject m_GameObject;
  9. protected bool m_Selected;
  10. protected bool m_Disabled;
  11. protected TabButtonGroup m_Group;
  12. public GameObject GameObject
  13. {
  14. get
  15. {
  16. return this.m_GameObject;
  17. }
  18. set
  19. {
  20. this.m_GameObject = value;
  21. this.Init();
  22. }
  23. }
  24. public bool Selected
  25. {
  26. get
  27. {
  28. return this.m_Selected;
  29. }
  30. set
  31. {
  32. if (this.m_Disabled)
  33. {
  34. return;
  35. }
  36. this.m_Selected = value;
  37. this.Render();
  38. }
  39. }
  40. public bool Disabled
  41. {
  42. get
  43. {
  44. return this.m_Disabled;
  45. }
  46. set
  47. {
  48. this.m_Disabled = value;
  49. this.Render();
  50. }
  51. }
  52. public TabButton(TabButtonGroup group)
  53. {
  54. this.m_Group = group;
  55. this.m_Group.Add(this);
  56. }
  57. public void Select()
  58. {
  59. if (this.m_Disabled)
  60. {
  61. return;
  62. }
  63. if (this.m_Selected)
  64. {
  65. return;
  66. }
  67. this.m_Group.Select(this);
  68. }
  69. public void OnDestroy()
  70. {
  71. this.m_Group.Remove(this);
  72. this.m_Group = null;
  73. }
  74. protected virtual void Init()
  75. {
  76. ClickEventTriggerListener.Get(this.m_GameObject).onPointerDown = new ClickEventTriggerListener.PointDelegate(this.OnDown);
  77. ClickEventTriggerListener.Get(this.m_GameObject).onPointerUp = new ClickEventTriggerListener.PointDelegate(this.OnUp);
  78. ClickEventTriggerListener.Get(this.m_GameObject).onPointerClick = new ClickEventTriggerListener.PointDelegate(this.OnClick);
  79. }
  80. protected virtual void OnDown(PointerEventData eventData)
  81. {
  82. }
  83. protected virtual void OnUp(PointerEventData eventData)
  84. {
  85. }
  86. protected virtual void OnClick(PointerEventData eventData)
  87. {
  88. this.Select();
  89. }
  90. protected virtual void Render()
  91. {
  92. }
  93. }