123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- public class uGUITabButton : Button
- {
- public bool isSelected
- {
- get
- {
- return this.selected_;
- }
- }
- public bool isEnabled
- {
- get
- {
- return base.enabled;
- }
- set
- {
- base.enabled = value;
- }
- }
- protected void OnInit()
- {
- this.isInit = true;
- this.backupDefaultColor = base.targetGraphic.color;
- this.isInitColor = true;
- if (this.selectSprite != null)
- {
- if (!this.selectSprite.enabled)
- {
- this.selectSprite.enabled = true;
- }
- this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 0f);
- }
- }
- public override void OnPointerClick(PointerEventData eventData)
- {
- if (uGUITabButton.current == null && base.enabled && base.interactable)
- {
- base.OnPointerClick(eventData);
- uGUITabButton.current = this;
- EventDelegate.Execute(this.onClickEvent);
- uGUITabButton.current = null;
- }
- }
- public void SetSelect(bool is_select)
- {
- if (!this.isInit)
- {
- this.OnInit();
- }
- if (!this.isInitColor)
- {
- this.backupDefaultColor = base.targetGraphic.color;
- this.isInitColor = true;
- }
- this.selected_ = is_select;
- if (is_select)
- {
- base.targetGraphic.color = base.colors.normalColor;
- if (this.selectSprite != null)
- {
- this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 1f);
- }
- uGUISelectableAnimation component = base.GetComponent<uGUISelectableAnimation>();
- if (component != null)
- {
- component.enabled = false;
- }
- if (this.maskObj != null)
- {
- this.maskObj.SetActive(true);
- }
- uGUITabButton uGUITabButton = uGUITabButton.current;
- uGUITabButton.current = this;
- uGUITabButton.selected = is_select;
- EventDelegate.Execute(this.onSelectEvent);
- uGUITabButton.selected = false;
- uGUITabButton.current = uGUITabButton;
- }
- else
- {
- base.targetGraphic.color = this.backupDefaultColor;
- if (this.selectSprite != null)
- {
- this.selectSprite.color = new Color(this.selectSprite.color.r, this.selectSprite.color.g, this.selectSprite.color.b, 0f);
- }
- uGUISelectableAnimation component2 = base.GetComponent<uGUISelectableAnimation>();
- if (component2 != null)
- {
- component2.enabled = true;
- }
- if (this.maskObj != null)
- {
- this.maskObj.SetActive(false);
- }
- }
- }
- public List<EventDelegate> onClickEvent = new List<EventDelegate>();
- public List<EventDelegate> onSelectEvent = new List<EventDelegate>();
- public Image selectSprite;
- public GameObject maskObj;
- protected bool selected_;
- public static bool selected;
- public static uGUITabButton current;
- private bool isInit;
- private bool isInitColor;
- protected Color backupDefaultColor;
- }
|