| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | [RequireComponent(typeof(BaseComponentView))] |
| | 6 | | public class UIUtil_ChangeTextAndIconColorOnFocus : MonoBehaviour |
| | 7 | | { |
| | 8 | | [SerializeField] internal TMP_Text textToChange; |
| | 9 | | [SerializeField] internal Image iconToChange; |
| | 10 | | [SerializeField] internal Color onFocusColor; |
| | 11 | | [SerializeField] internal Color onLoseFocusColor; |
| | 12 | |
|
| | 13 | | internal BaseComponentView componentView; |
| | 14 | |
|
| | 15 | | private void Awake() |
| | 16 | | { |
| 998 | 17 | | componentView = GetComponent<BaseComponentView>(); |
| 998 | 18 | | } |
| | 19 | |
|
| | 20 | | private void Start() |
| | 21 | | { |
| 1 | 22 | | componentView.onFocused += ComponentView_onFocused; |
| 1 | 23 | | ComponentView_onFocused(componentView.isFocused); |
| 1 | 24 | | } |
| | 25 | |
|
| | 26 | | private void OnDestroy() |
| | 27 | | { |
| 998 | 28 | | componentView.onFocused -= ComponentView_onFocused; |
| 998 | 29 | | } |
| | 30 | |
|
| | 31 | | private void ComponentView_onFocused(bool isFocused) |
| | 32 | | { |
| 3 | 33 | | textToChange.color = isFocused ? onFocusColor : onLoseFocusColor; |
| 3 | 34 | | iconToChange.color = isFocused ? onFocusColor : onLoseFocusColor; |
| 3 | 35 | | } |
| | 36 | | } |