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

32 lines
736 B
C#
Raw Normal View History

2020-03-01 20:26:06 -05:00
using UnityEngine;
using UnityEngine.UI;
2020-03-01 20:26:06 -05:00
namespace UnityAtoms.MonoHooks
{
/// <summary>
/// Mono Hook for On Button Click
/// </summary>
[EditorIcon("atom-icon-delicate")]
[AddComponentMenu("Unity Atoms/Hooks/On Button Click Hook")]
[RequireComponent(typeof(Button))]
public sealed class OnButtonClickHook : VoidHook
{
private void Awake()
{
var button = GetComponent<Button>();
button.onClick.AddListener(OnClick);
}
2020-03-01 20:26:06 -05:00
private void OnDestroy()
{
var button = GetComponent<Button>();
button.onClick.RemoveListener(OnClick);
}
2020-03-01 20:26:06 -05:00
private void OnClick()
{
OnHook();
}
}
}