mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 00:28:23 -05:00
23a8873462
* changed AddComponentMenu names for Listeners * renamed AddComponentMenu Listeners names in other packages * renamed AddComponentMenu for hooks * renamed double Listeners to "x 2" convention
32 lines
746 B
C#
32 lines
746 B
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
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);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
var button = GetComponent<Button>();
|
|
button.onClick.RemoveListener(OnClick);
|
|
}
|
|
|
|
private void OnClick()
|
|
{
|
|
OnHook(new Void());
|
|
}
|
|
}
|
|
}
|