69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Titles
|
|
{
|
|
public class TitleMenuButton : MonoBehaviour, ISelectHandler, IDeselectHandler, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
[SerializeField, Required]
|
|
private Button _targetButton;
|
|
|
|
[SerializeField, Required]
|
|
private Image _selectedImage;
|
|
|
|
[SerializeField]
|
|
private Color _highlightedColor;
|
|
|
|
private Color _originalColor = Color.white;
|
|
private bool _isQuitting;
|
|
|
|
private void OnApplicationQuit()
|
|
{
|
|
_isQuitting = true;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (EventSystem.current.currentSelectedGameObject != gameObject) return;
|
|
|
|
_selectedImage.enabled = true;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_selectedImage.enabled = false;
|
|
}
|
|
|
|
public void OnSelect(BaseEventData eventData)
|
|
{
|
|
_selectedImage.color = _originalColor;
|
|
_selectedImage.enabled = true;
|
|
}
|
|
|
|
public void OnDeselect(BaseEventData eventData)
|
|
{
|
|
_selectedImage.enabled = false;
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (EventSystem.current.currentSelectedGameObject == gameObject) return;
|
|
|
|
_selectedImage.color = _highlightedColor;
|
|
_selectedImage.enabled = true;
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (_isQuitting || EventSystem.current?.currentSelectedGameObject == gameObject) return;
|
|
|
|
_selectedImage.color = _originalColor;
|
|
_selectedImage.enabled = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
|