Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#271 Add event references to VoidHook and OnAwakeHook v5 #288

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Packages/MonoHooks/Runtime/Hooks/OnAwakeHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public sealed class OnAwakeHook : VoidHook
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)
if (_eventReference != null && _listener != null)
{
_event.RegisterListener(_listener);
_eventReference.Event.RegisterListener(_listener);
}
if (_eventWithGameObjectReference != null && _gameObjectListener != null)
{
_eventWithGameObjectReference.RegisterListener(_gameObjectListener);
_eventWithGameObjectReference.Event.RegisterListener(_gameObjectListener);
}

OnHook();
Expand Down
12 changes: 6 additions & 6 deletions Packages/MonoHooks/Runtime/Hooks/VoidHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public abstract class VoidHook : MonoBehaviour
/// The Event
/// </summary>
[SerializeField]
protected VoidEvent _event;
protected VoidBaseEventReference _eventReference;

/// <summary>
/// Event including a GameObject reference.
/// </summary>
[SerializeField]
protected GameObjectEvent _eventWithGameObjectReference;
protected GameObjectEventReference _eventWithGameObjectReference;

/// <summary>
/// Selector function for the Event `EventWithGameObjectReference`. Makes it possible to for example select the parent GameObject and pass that a long to the `EventWithGameObjectReference`.
Expand All @@ -29,13 +29,13 @@ public abstract class VoidHook : MonoBehaviour

protected void OnHook()
{
if (_event != null)
if (_eventReference != null && _eventReference.Event != null)
{
_event.Raise();
_eventReference.Event.Raise();
}
if (_eventWithGameObjectReference != null)
if (_eventWithGameObjectReference != null && _eventWithGameObjectReference.Event != null)
{
_eventWithGameObjectReference.Raise(_selectGameObjectReference != null ? _selectGameObjectReference.Call(gameObject) : gameObject);
_eventWithGameObjectReference.Event.Raise(_selectGameObjectReference != null ? _selectGameObjectReference.Call(gameObject) : gameObject);
}
}
}
Expand Down