mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-24 00:58:59 -05:00
43 lines
1.3 KiB
C#
43 lines
1.3 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")]
|
|
public sealed class OnAwakeHook : VoidHook
|
|
{
|
|
/// <summary>
|
|
/// Listener
|
|
/// </summary>
|
|
[FormerlySerializedAs("listener")]
|
|
[SerializeField]
|
|
private VoidListener _listener;
|
|
|
|
/// <summary>
|
|
/// Listener with GameObject reference
|
|
/// </summary>
|
|
[FormerlySerializedAs("listenerWithGO")]
|
|
[SerializeField]
|
|
private VoidGameObjectListener _listenerWithGameObject;
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|