mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
OnButtonClickHook should require Button
This commit is contained in:
parent
ab02061f12
commit
c97e541641
@ -1,23 +1,45 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UnityAtoms
|
||||
{
|
||||
public class OnButtonClickHook : VoidHook
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
GetComponent<Button>().onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
GetComponent<Button>().onClick.RemoveListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
OnHook(new Void());
|
||||
}
|
||||
}
|
||||
}
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityAtoms.Logger;
|
||||
#endif
|
||||
|
||||
namespace UnityAtoms
|
||||
{
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class OnButtonClickHook : VoidHook
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
var button = GetComponent<Button>();
|
||||
if (button == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AtomsLogger.Warning("OnButtonClickHook needs a Button component");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
button.onClick.AddListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
var button = GetComponent<Button>();
|
||||
if (button == null)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AtomsLogger.Warning("OnButtonClickHook needs a Button component");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
button.onClick.RemoveListener(OnClick);
|
||||
}
|
||||
|
||||
private void OnClick()
|
||||
{
|
||||
OnHook(new Void());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user