2019-07-05 10:07:05 +02:00
|
|
|
|
using UnityEngine;
|
2019-04-05 14:37:48 +02:00
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
2019-07-05 10:07:05 +02:00
|
|
|
|
namespace UnityAtoms.Examples
|
2019-04-05 14:37:48 +02:00
|
|
|
|
{
|
|
|
|
|
[RequireComponent(typeof(Button))]
|
2019-07-05 10:07:05 +02:00
|
|
|
|
public sealed class RaiseEventOnButtonClick : MonoBehaviour
|
2019-04-05 14:37:48 +02:00
|
|
|
|
{
|
2019-07-05 10:07:05 +02:00
|
|
|
|
[SerializeField]
|
|
|
|
|
private VoidEvent _event;
|
|
|
|
|
|
2019-04-05 14:37:48 +02:00
|
|
|
|
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-07-05 10:07:05 +02:00
|
|
|
|
_event.Raise();
|
2019-04-05 14:37:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|