diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/ListMenuButton.cs |
+ init
Diffstat (limited to 'GameCode/ListMenuButton.cs')
-rw-r--r-- | GameCode/ListMenuButton.cs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/GameCode/ListMenuButton.cs b/GameCode/ListMenuButton.cs new file mode 100644 index 0000000..b208a12 --- /dev/null +++ b/GameCode/ListMenuButton.cs @@ -0,0 +1,102 @@ +using SoundImplementation; +using TMPro; +using UnityEngine; +using UnityEngine.EventSystems; + +public class ListMenuButton : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, IPointerEnterHandler, IPointerExitHandler, IUpdateSelectedHandler, ISelectHandler +{ + private TextMeshProUGUI text; + + private Color defaultColor; + + private Vector3 defaultPos; + + public bool changeFontSize = true; + + public bool hideBar; + + public float setBarHeight; + + public bool toggleTextColor; + + public Color selectedTextColor; + + public Color defaultTextColor; + + private float smallFont = 40f; + + private bool inited; + + private void Awake() + { + } + + private void Start() + { + Init(); + smallFont = text.fontSize; + defaultPos = text.transform.localPosition; + defaultColor = text.color; + } + + public void Nope() + { + Init(); + MenuEffects.instance.BlinkInColor(text, MenuEffects.instance.nopeColor, defaultColor, 0.15f); + MenuEffects.instance.ShakeObject(text.gameObject, defaultPos, 15f, 0.2f); + } + + public void Deselect() + { + Init(); + text.fontStyle = FontStyles.Normal; + _ = changeFontSize; + if (toggleTextColor) + { + GetComponentInChildren<TextMeshProUGUI>().color = defaultTextColor; + } + } + + public void Select() + { + Init(); + text.fontStyle = FontStyles.Bold; + _ = changeFontSize; + if (toggleTextColor) + { + GetComponentInChildren<TextMeshProUGUI>().color = selectedTextColor; + } + } + + public void OnPointerClick(PointerEventData eventData) + { + SoundPlayerStatic.Instance.PlayButtonClick(); + } + + public void OnPointerEnter(PointerEventData eventData) + { + ListMenu.instance.SelectButton(this); + } + + public void OnPointerExit(PointerEventData eventData) + { + } + + public void OnUpdateSelected(BaseEventData eventData) + { + } + + public void OnSelect(BaseEventData eventData) + { + ListMenu.instance.SelectButton(this); + } + + private void Init() + { + if (!inited) + { + inited = true; + text = GetComponentInChildren<TextMeshProUGUI>(); + } + } +} |