unity-atoms/Packages/MonoHooks/Runtime/Hooks/OnAwakeHook.cs
IceTrooper 23a8873462 Changed AddComponentMenu names for Listeners/Hooks (#84)
* changed AddComponentMenu names for Listeners

* renamed AddComponentMenu Listeners names in other packages

* renamed AddComponentMenu for hooks

* renamed double Listeners to "x 2" convention
2019-11-13 08:59:39 +01:00

41 lines
1.2 KiB
C#

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")]
[AddComponentMenu("Unity Atoms/Hooks/On Awake Hook")]
public sealed class OnAwakeHook : VoidHook
{
/// <summary>
/// Listener
/// </summary>
[SerializeField]
private VoidListener _listener = null;
/// <summary>
/// Listener with GameObject reference
/// </summary>
[SerializeField]
private VoidGameObjectListener _listenerWithGameObject = null;
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());
}
}
}