uGUITabButton.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using UnityEngine.UI;
  6. public class uGUITabButton : Button
  7. {
  8. public bool isSelected
  9. {
  10. get
  11. {
  12. return this.selected_;
  13. }
  14. }
  15. public bool isEnabled
  16. {
  17. get
  18. {
  19. return base.enabled;
  20. }
  21. set
  22. {
  23. base.enabled = value;
  24. }
  25. }
  26. protected void OnInit()
  27. {
  28. this.isInit = true;
  29. this.backupDefaultColor = base.targetGraphic.color;
  30. this.isInitColor = true;
  31. if (this.selectSprite != null)
  32. {
  33. if (!this.selectSprite.enabled)
  34. {
  35. this.selectSprite.enabled = true;
  36. }
  37. this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 0f);
  38. }
  39. }
  40. public override void OnPointerClick(PointerEventData eventData)
  41. {
  42. if (uGUITabButton.current == null && base.enabled && base.interactable)
  43. {
  44. base.OnPointerClick(eventData);
  45. uGUITabButton.current = this;
  46. EventDelegate.Execute(this.onClickEvent);
  47. uGUITabButton.current = null;
  48. }
  49. }
  50. public void SetSelect(bool is_select)
  51. {
  52. if (!this.isInit)
  53. {
  54. this.OnInit();
  55. }
  56. if (!this.isInitColor)
  57. {
  58. this.backupDefaultColor = base.targetGraphic.color;
  59. this.isInitColor = true;
  60. }
  61. this.selected_ = is_select;
  62. if (is_select)
  63. {
  64. base.targetGraphic.color = base.colors.normalColor;
  65. if (this.selectSprite != null)
  66. {
  67. this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 1f);
  68. }
  69. uGUISelectableAnimation component = base.GetComponent<uGUISelectableAnimation>();
  70. if (component != null)
  71. {
  72. component.enabled = false;
  73. }
  74. if (this.maskObj != null)
  75. {
  76. this.maskObj.SetActive(true);
  77. }
  78. uGUITabButton uGUITabButton = uGUITabButton.current;
  79. uGUITabButton.current = this;
  80. uGUITabButton.selected = is_select;
  81. EventDelegate.Execute(this.onSelectEvent);
  82. uGUITabButton.selected = false;
  83. uGUITabButton.current = uGUITabButton;
  84. }
  85. else
  86. {
  87. base.targetGraphic.color = this.backupDefaultColor;
  88. if (this.selectSprite != null)
  89. {
  90. this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 0f);
  91. }
  92. uGUISelectableAnimation component2 = base.GetComponent<uGUISelectableAnimation>();
  93. if (component2 != null)
  94. {
  95. component2.enabled = true;
  96. }
  97. if (this.maskObj != null)
  98. {
  99. this.maskObj.SetActive(false);
  100. }
  101. }
  102. }
  103. public List<EventDelegate> onClickEvent = new List<EventDelegate>();
  104. public List<EventDelegate> onSelectEvent = new List<EventDelegate>();
  105. public Image selectSprite;
  106. public GameObject maskObj;
  107. protected bool selected_;
  108. public static bool selected;
  109. public static uGUITabButton current;
  110. private bool isInit;
  111. private bool isInitColor;
  112. protected Color backupDefaultColor;
  113. }