mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
fix #321 NRE when Event Reference Listeners event reference is not set
This commit is contained in:
parent
a35e7342cc
commit
46037ac590
@ -27,9 +27,12 @@ namespace UnityAtoms
|
||||
{
|
||||
switch (_usage)
|
||||
{
|
||||
case (AtomEventReferenceUsage.VARIABLE): return _variable.GetOrCreateEvent<E>();
|
||||
case (AtomEventReferenceUsage.VARIABLE_INSTANCER): return _variableInstancer.GetOrCreateEvent<E>();
|
||||
case (AtomEventReferenceUsage.EVENT_INSTANCER): return _eventInstancer.Event;
|
||||
case (AtomEventReferenceUsage.VARIABLE):
|
||||
return _variable == null ? LogNullReference(nameof(_variable)) : _variable.GetOrCreateEvent<E>();
|
||||
case (AtomEventReferenceUsage.VARIABLE_INSTANCER):
|
||||
return _variableInstancer == null ? LogNullReference(nameof(_variableInstancer)) : _variableInstancer.GetOrCreateEvent<E>();
|
||||
case (AtomEventReferenceUsage.EVENT_INSTANCER):
|
||||
return _eventInstancer == null ? LogNullReference(nameof(_eventInstancer)) : _eventInstancer.Event;
|
||||
case (AtomEventReferenceUsage.EVENT):
|
||||
default:
|
||||
return _event;
|
||||
@ -81,5 +84,17 @@ namespace UnityAtoms
|
||||
{
|
||||
return reference.Event;
|
||||
}
|
||||
|
||||
private E LogNullReference(string atomEventReferenceUsage)
|
||||
{
|
||||
if (AtomPreferences.IsDebugModeEnabled)
|
||||
{
|
||||
throw new NullReferenceException($"{atomEventReferenceUsage} reference is missing in inspector.");
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user