123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- using System;
- using UnityEngine;
- using UnityEngine.EventSystems;
- public class NormalTabButton : TabButton
- {
- private Transform m_NormalBg;
- private Transform m_SelectedBg;
- private Transform m_DisabledBg;
- protected Transform m_NormalTxt;
- protected Transform m_SelectedTxt;
- protected Transform m_DisabledTxt;
- public NormalTabButton(TabButtonGroup group) : base(group)
- {
- }
- protected override void Init()
- {
- base.Init();
- this.m_NormalBg = this.m_GameObject.transform.Find("Normal");
- this.m_SelectedBg = this.m_GameObject.transform.Find("Selected");
- this.m_DisabledBg = this.m_GameObject.transform.Find("Disabled");
- this.m_NormalTxt = this.m_GameObject.transform.Find("NormalTxt");
- this.m_SelectedTxt = this.m_GameObject.transform.Find("SelectedTxt");
- this.m_DisabledTxt = this.m_GameObject.transform.Find("DisabledTxt");
- }
- protected override void Render()
- {
- base.Render();
- if (this.m_Disabled)
- {
- this.ChangeState(ESelectionState.Disabled);
- }
- else
- {
- if (this.m_Selected)
- {
- this.ChangeState(ESelectionState.Pressed);
- }
- else
- {
- this.ChangeState(ESelectionState.Normal);
- }
- }
- }
- protected override void OnDown(PointerEventData eventData)
- {
- base.OnDown(eventData);
- }
- protected override void OnUp(PointerEventData eventData)
- {
- base.OnUp(eventData);
- if (base.Disabled)
- {
- return;
- }
- if (!base.Selected)
- {
- this.ChangeState(ESelectionState.Normal);
- }
- }
- private void ChangeState(ESelectionState state)
- {
- if (this.m_NormalBg != null)
- {
- this.m_NormalBg.gameObject.SetActive(state == ESelectionState.Normal);
- }
- if (this.m_SelectedBg != null)
- {
- this.m_SelectedBg.gameObject.SetActive(state == ESelectionState.Pressed);
- }
- if (this.m_DisabledBg != null)
- {
- this.m_DisabledBg.gameObject.SetActive(state == ESelectionState.Disabled);
- }
- if (this.m_NormalTxt != null)
- {
- this.m_NormalTxt.gameObject.SetActive(state == ESelectionState.Normal);
- }
- if (this.m_SelectedTxt != null)
- {
- this.m_SelectedTxt.gameObject.SetActive(state == ESelectionState.Pressed);
- }
- if (this.m_DisabledTxt != null)
- {
- this.m_DisabledTxt.gameObject.SetActive(state == ESelectionState.Disabled);
- }
- }
- }
- public enum ESelectionState
- {
- Normal,
- Pressed,
- Disabled
- }
|