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

41 lines
1.2 KiB
C#
Raw Normal View History

2020-03-01 20:26:06 -05:00
using UnityEngine;
using UnityAtoms.BaseAtoms;
2019-10-15 19:43:51 -04:00
2020-03-01 20:26:06 -05:00
namespace UnityAtoms.MonoHooks
{
/// <summary>
/// Mono Hook for [`Awake`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html).
/// </summary>
[EditorIcon("atom-icon-delicate")]
[AddComponentMenu("Unity Atoms/Hooks/On Awake Hook")]
public sealed class OnAwakeHook : VoidHook
{
/// <summary>
/// Listener
/// </summary>
[SerializeField]
private VoidListener _listener = null;
2019-10-15 19:43:51 -04:00
2020-03-01 20:26:06 -05:00
/// <summary>
/// Listener with GameObject reference
/// </summary>
[SerializeField]
private GameObjectEventReferenceListener _gameObjectListener = null;
2019-10-15 19:43:51 -04:00
2020-03-01 20:26:06 -05: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 && _gameObjectListener != null)
{
_eventWithGameObjectReference.RegisterListener(_gameObjectListener);
}
2019-10-15 19:43:51 -04:00
2020-03-01 20:26:06 -05:00
OnHook();
}
}
}