NormalTabButton.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.EventSystems;
  4. public class NormalTabButton : TabButton
  5. {
  6. private Transform m_NormalBg;
  7. private Transform m_SelectedBg;
  8. private Transform m_DisabledBg;
  9. protected Transform m_NormalTxt;
  10. protected Transform m_SelectedTxt;
  11. protected Transform m_DisabledTxt;
  12. public NormalTabButton(TabButtonGroup group) : base(group)
  13. {
  14. }
  15. protected override void Init()
  16. {
  17. base.Init();
  18. this.m_NormalBg = this.m_GameObject.transform.Find("Normal");
  19. this.m_SelectedBg = this.m_GameObject.transform.Find("Selected");
  20. this.m_DisabledBg = this.m_GameObject.transform.Find("Disabled");
  21. this.m_NormalTxt = this.m_GameObject.transform.Find("NormalTxt");
  22. this.m_SelectedTxt = this.m_GameObject.transform.Find("SelectedTxt");
  23. this.m_DisabledTxt = this.m_GameObject.transform.Find("DisabledTxt");
  24. }
  25. protected override void Render()
  26. {
  27. base.Render();
  28. if (this.m_Disabled)
  29. {
  30. this.ChangeState(ESelectionState.Disabled);
  31. }
  32. else
  33. {
  34. if (this.m_Selected)
  35. {
  36. this.ChangeState(ESelectionState.Pressed);
  37. }
  38. else
  39. {
  40. this.ChangeState(ESelectionState.Normal);
  41. }
  42. }
  43. }
  44. protected override void OnDown(PointerEventData eventData)
  45. {
  46. base.OnDown(eventData);
  47. }
  48. protected override void OnUp(PointerEventData eventData)
  49. {
  50. base.OnUp(eventData);
  51. if (base.Disabled)
  52. {
  53. return;
  54. }
  55. if (!base.Selected)
  56. {
  57. this.ChangeState(ESelectionState.Normal);
  58. }
  59. }
  60. private void ChangeState(ESelectionState state)
  61. {
  62. if (this.m_NormalBg != null)
  63. {
  64. this.m_NormalBg.gameObject.SetActive(state == ESelectionState.Normal);
  65. }
  66. if (this.m_SelectedBg != null)
  67. {
  68. this.m_SelectedBg.gameObject.SetActive(state == ESelectionState.Pressed);
  69. }
  70. if (this.m_DisabledBg != null)
  71. {
  72. this.m_DisabledBg.gameObject.SetActive(state == ESelectionState.Disabled);
  73. }
  74. if (this.m_NormalTxt != null)
  75. {
  76. this.m_NormalTxt.gameObject.SetActive(state == ESelectionState.Normal);
  77. }
  78. if (this.m_SelectedTxt != null)
  79. {
  80. this.m_SelectedTxt.gameObject.SetActive(state == ESelectionState.Pressed);
  81. }
  82. if (this.m_DisabledTxt != null)
  83. {
  84. this.m_DisabledTxt.gameObject.SetActive(state == ESelectionState.Disabled);
  85. }
  86. }
  87. }
  88. public enum ESelectionState
  89. {
  90. Normal,
  91. Pressed,
  92. Disabled
  93. }