2019-10-15 19:43:51 -04:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Serialization;
|
|
|
|
|
|
|
|
namespace UnityAtoms.MonoHooks
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Mono Hook for [`Awake`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html).
|
|
|
|
/// </summary>
|
|
|
|
[EditorIcon("atom-icon-delicate")]
|
2019-11-13 02:59:39 -05:00
|
|
|
[AddComponentMenu("Unity Atoms/Hooks/On Awake Hook")]
|
2019-10-15 19:43:51 -04:00
|
|
|
public sealed class OnAwakeHook : VoidHook
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Listener
|
|
|
|
/// </summary>
|
|
|
|
[SerializeField]
|
2019-10-20 15:16:07 -04:00
|
|
|
private VoidListener _listener = null;
|
2019-10-15 19:43:51 -04:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Listener with GameObject reference
|
|
|
|
/// </summary>
|
|
|
|
[SerializeField]
|
2019-10-20 15:16:07 -04:00
|
|
|
private VoidGameObjectListener _listenerWithGameObject = null;
|
2019-10-15 19:43:51 -04:00
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
// This is needed because it's not certain that OnEnable on all scripts are called before Awake on all scripts
|
|
|
|
if (Event != null && _listener != null)
|
|
|
|
{
|
|
|
|
Event.RegisterListener(_listener);
|
|
|
|
}
|
|
|
|
if (EventWithGameObjectReference != null && _listenerWithGameObject != null)
|
|
|
|
{
|
|
|
|
EventWithGameObjectReference.RegisterListener(_listenerWithGameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
OnHook(new Void());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|