mirror of
https://github.com/ConjureETS/Unity_Utils.git
synced 2026-03-23 20:40:58 +00:00
62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Canvases.Components
|
|
{
|
|
public class ButtonUIComponent : UISelectableComponentBase
|
|
{
|
|
public event Action OnClick;
|
|
|
|
[Header("Association"), SerializeField, Required]
|
|
private Button button;
|
|
|
|
[Header("Configuration"), SerializeField]
|
|
private ButtonNavigationType buttonNavigationType;
|
|
|
|
private enum ButtonNavigationType
|
|
{
|
|
Forward,
|
|
Backward
|
|
}
|
|
|
|
public Color Color
|
|
{
|
|
set => button.image.color = value;
|
|
}
|
|
|
|
public bool Enabled
|
|
{
|
|
set => button.interactable = value;
|
|
}
|
|
|
|
public void Select() => button.Select();
|
|
|
|
protected override void SetSelectableGameObject() => Selectable = button;
|
|
|
|
private void Start()
|
|
{
|
|
Debug.Assert(button, $"A {nameof(button)} must be assigned to a {nameof(ButtonUIComponent)}");
|
|
button.onClick.AddListener(OnButtonClicked);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
button.onClick.RemoveListener(OnButtonClicked);
|
|
base.OnDestroy();
|
|
}
|
|
|
|
private void OnButtonClicked()
|
|
{
|
|
// PlayClickedSound();
|
|
OnClick?.Invoke();
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
if (!button)
|
|
button = GetComponent<Button>();
|
|
}
|
|
}
|
|
} |