unity-atoms/Packages/MonoHooks/Runtime/Hooks/OnButtonClickHook.cs

32 lines
746 B
C#
Raw Normal View History

2019-10-15 19:43:51 -04:00
using UnityEngine;
using UnityEngine.UI;
2019-10-15 19:43:51 -04:00
namespace UnityAtoms.MonoHooks
{
2019-10-15 19:43:51 -04:00
/// <summary>
/// Mono Hook for On Button Click
/// </summary>
[EditorIcon("atom-icon-delicate")]
[AddComponentMenu("Unity Atoms/Hooks/On Button Click Hook")]
[RequireComponent(typeof(Button))]
2019-10-15 19:43:51 -04:00
public sealed class OnButtonClickHook : VoidHook
{
private void Awake()
{
var button = GetComponent<Button>();
button.onClick.AddListener(OnClick);
}
private void OnDestroy()
{
var button = GetComponent<Button>();
button.onClick.RemoveListener(OnClick);
}
private void OnClick()
{
2019-10-15 19:43:51 -04:00
OnHook(new Void());
}
}
}