|
|
@@ -0,0 +1,209 @@
|
|
|
+using DG.Tweening;
|
|
|
+using QFramework;
|
|
|
+using Sirenix.OdinInspector;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+using UnityEngine.EventSystems;
|
|
|
+using UnityEngine.UI;
|
|
|
+
|
|
|
+public enum BtnState
|
|
|
+{
|
|
|
+ normal,
|
|
|
+ highter,
|
|
|
+ select
|
|
|
+}
|
|
|
+
|
|
|
+/// <summary>
|
|
|
+/// 底部按钮
|
|
|
+/// </summary>
|
|
|
+public class DownBGButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
|
|
+{
|
|
|
+ private RectTransform m_RectTransform;
|
|
|
+ private Button m_Btn;
|
|
|
+ private Text m_BtnText;
|
|
|
+ private Image m_BtnIcon;
|
|
|
+ private Image m_PromptIcon;
|
|
|
+ private Image m_HighlighterArea;
|
|
|
+ private Image m_SelectLine;
|
|
|
+ public Button Button
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ if (m_Btn == null)
|
|
|
+ {
|
|
|
+ m_Btn = GetComponent<Button>();
|
|
|
+ }
|
|
|
+ return m_Btn;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [LabelText("常态Icon")]
|
|
|
+ public Sprite m_NormalIcon;
|
|
|
+ [LabelText("划入Icon")]
|
|
|
+ public Sprite m_HoverIcon;
|
|
|
+ [LabelText("选中Icon")]
|
|
|
+ public Sprite m_SelectIcon;
|
|
|
+
|
|
|
+ [LabelText("常态颜色")]
|
|
|
+ public Color m_NormalColor;
|
|
|
+ [LabelText("划入颜色")]
|
|
|
+ public Color m_HoverColor;
|
|
|
+ [LabelText("选中字体颜色")]
|
|
|
+ public Color m_SelectColor;
|
|
|
+
|
|
|
+ [LabelText("常态字体")]
|
|
|
+ public Font m_NormalFont;
|
|
|
+ [LabelText("划入字体")]
|
|
|
+ public Font m_HoverFont;
|
|
|
+ [LabelText("选中字体")]
|
|
|
+ public Font m_SelectFont;
|
|
|
+
|
|
|
+
|
|
|
+ //是否是状态切换类按钮 true:状态切换 false :点击类
|
|
|
+ private bool isSelect = false;
|
|
|
+ private bool isPrompting = false;
|
|
|
+ private bool isHover = false;
|
|
|
+
|
|
|
+ public void Awake()
|
|
|
+ {
|
|
|
+ Load();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void Load()
|
|
|
+ {
|
|
|
+ m_RectTransform = GetComponent<RectTransform>();
|
|
|
+ m_Btn = GetComponent<Button>();
|
|
|
+ m_BtnIcon = this.transform.Find("Icon").GetComponent<Image>();
|
|
|
+ m_BtnText = m_BtnIcon.transform.Find("Text").GetComponent<Text>();
|
|
|
+ m_HighlighterArea = this.transform.Find("SelectArea").GetComponent<Image>();
|
|
|
+ m_SelectLine = this.transform.Find("Line").GetComponent<Image>();
|
|
|
+ m_PromptIcon = this.transform.Find("PromptIcon").GetComponent<Image>();
|
|
|
+
|
|
|
+ m_HighlighterArea.gameObject.SetActive(false);
|
|
|
+ m_SelectLine.gameObject.SetActive(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RefrushButonSize()
|
|
|
+ {
|
|
|
+ m_PromptIcon.rectTransform.sizeDelta = m_RectTransform.sizeDelta;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void SetBtnState(BtnState state)
|
|
|
+ {
|
|
|
+ isHover = false;
|
|
|
+ switch (state)
|
|
|
+ {
|
|
|
+ case BtnState.normal:
|
|
|
+ m_BtnIcon.sprite = m_NormalIcon;
|
|
|
+ m_BtnText.font = m_NormalFont;
|
|
|
+ m_BtnText.color = m_NormalColor;
|
|
|
+ m_HighlighterArea.gameObject.SetActive(false);
|
|
|
+ m_SelectLine.gameObject.SetActive(false);
|
|
|
+ isSelect = false;
|
|
|
+ break;
|
|
|
+ case BtnState.highter:
|
|
|
+ m_BtnIcon.sprite = m_HoverIcon;
|
|
|
+ m_BtnText.font = m_HoverFont;
|
|
|
+ m_BtnText.color = m_HoverColor;
|
|
|
+ m_HighlighterArea.gameObject.SetActive(true);
|
|
|
+ m_SelectLine.gameObject.SetActive(true);
|
|
|
+
|
|
|
+ isHover = true;
|
|
|
+ break;
|
|
|
+ case BtnState.select:
|
|
|
+ m_BtnIcon.sprite = m_SelectIcon;
|
|
|
+ m_BtnText.font = m_SelectFont;
|
|
|
+ m_BtnText.color = m_SelectColor;
|
|
|
+ m_HighlighterArea.gameObject.SetActive(false);
|
|
|
+ m_SelectLine.gameObject.SetActive(true);
|
|
|
+ isSelect = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void OnPointerEnter(PointerEventData eventData)
|
|
|
+ {
|
|
|
+ //HoverClosePrompt();
|
|
|
+
|
|
|
+ if (!isSelect)
|
|
|
+ {
|
|
|
+ SetBtnState(BtnState.highter);
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ SetBtnState(BtnState.select);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void OnPointerExit(PointerEventData eventData)
|
|
|
+ {
|
|
|
+ if (isSelect)
|
|
|
+ {
|
|
|
+ SetBtnState(BtnState.select);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SetBtnState(BtnState.normal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ void OnEnable()
|
|
|
+ {
|
|
|
+ LocalizationManager_OnLocalizeEvent();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void LocalizationManager_OnLocalizeEvent()
|
|
|
+ {
|
|
|
+ RefrushButonSize();
|
|
|
+
|
|
|
+ if(isPrompting)
|
|
|
+ {
|
|
|
+ m_PromptIcon.rectTransform.DOKill();
|
|
|
+ m_PromptIcon.rectTransform.sizeDelta = m_RectTransform.sizeDelta;
|
|
|
+ m_PromptIcon.rectTransform.DOSizeDelta(new Vector2(m_RectTransform.sizeDelta.x - 34, m_BtnText.rectTransform.sizeDelta.y + 2), 1).SetLoops(-1, LoopType.Yoyo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 开启按钮提示
|
|
|
+ /// </summary>
|
|
|
+ public void OpenPrompt()
|
|
|
+ {
|
|
|
+ if (isPrompting) return;
|
|
|
+
|
|
|
+ m_PromptIcon.gameObject.SetActive(true);
|
|
|
+ m_PromptIcon.rectTransform.sizeDelta = m_RectTransform.sizeDelta;
|
|
|
+ m_PromptIcon.rectTransform.DOSizeDelta(new Vector2(m_RectTransform.sizeDelta.x - 34, m_BtnText.rectTransform.sizeDelta.y + 2), 1).SetLoops(-1, LoopType.Yoyo);
|
|
|
+ isPrompting=true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 关闭按钮提示
|
|
|
+ /// </summary>
|
|
|
+ public void ClosePrompt()
|
|
|
+ {
|
|
|
+ if (!isPrompting || !m_PromptIcon.gameObject.activeSelf) return;
|
|
|
+
|
|
|
+ isPrompting=false;
|
|
|
+ m_PromptIcon.rectTransform.DOKill();
|
|
|
+ m_PromptIcon.gameObject.SetActive(false);
|
|
|
+ m_PromptIcon.rectTransform.sizeDelta = m_RectTransform.sizeDelta;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void HoverOpenPrompt()
|
|
|
+ {
|
|
|
+ if (isPrompting)
|
|
|
+ {
|
|
|
+ m_PromptIcon.rectTransform.DOPlay();
|
|
|
+ m_PromptIcon.gameObject.SetActive(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void HoverClosePrompt()
|
|
|
+ {
|
|
|
+ if (isPrompting)
|
|
|
+ {
|
|
|
+ m_PromptIcon.rectTransform.DOPause();
|
|
|
+ m_PromptIcon.gameObject.SetActive(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|