using UnityEngine; using UnityEngine.UI; using TMPro; public class UIButtonHighlight : MonoBehaviour { public GameObject[] highlightObjects; // �������� (�����/������), ������� ������ ���� public Color normalColor = Color.white; // ���� ���� ������ public Color highlightedColor = Color.yellow; // ���� ���� ��� ��������� public Color highlightOnColor = Color.yellow; // ���� highlight-�������� ����� ������� public Color highlightOffColor = Color.white; // ���� highlight-�������� ����� �� ������� private Image buttonImage; private TextMeshProUGUI buttonText; private Color originalTextColor; public Color disabledTextColor = Color.gray; public System.Action onFocused; // вызывается когда кнопка получает фокус void Awake() { buttonImage = GetComponent(); buttonText = GetComponentInChildren(); if (buttonText != null) originalTextColor = buttonText.color; SetHighlighted(false); } public void SetHighlighted(bool state) { // ������ ���� ���� ������ if (buttonImage != null) buttonImage.color = state ? highlightedColor : normalColor; // ������ ���� ������ if (buttonText != null) buttonText.color = state ? originalTextColor : disabledTextColor; // ������ ���� ���� highlight-�������� if (highlightObjects != null) { foreach (var obj in highlightObjects) { if (!obj) continue; // 1. ���� Image var img = obj.GetComponent(); if (img != null) { img.color = state ? highlightOnColor : highlightOffColor; continue; } // 2. ��� SpriteRenderer var sr = obj.GetComponent(); if (sr != null) { sr.color = state ? highlightOnColor : highlightOffColor; continue; } } } if (state) onFocused?.Invoke(); } }