Error Handling

This commit is contained in:
Syntriax 2022-11-21 22:18:47 +03:00
parent 54168a4a4d
commit d40132370d
1 changed files with 23 additions and 8 deletions

View File

@ -16,26 +16,41 @@ namespace Syntriax.Modules.Factory
if (IsInitialized) if (IsInitialized)
return; return;
OnFactoryInitialize();
IsInitialized = true; IsInitialized = true;
try
{
OnFactoryInitialize();
OnInitialized?.Invoke(this); OnInitialized?.Invoke(this);
OnStateChanged?.Invoke(this); OnStateChanged?.Invoke(this);
} }
catch (System.Exception e)
{
Debug.LogError(e);
Reset();
}
}
public void Reset() public void Reset()
{ {
if (!IsInitialized) if (!IsInitialized)
return; return;
OnFactoryReset();
IsInitialized = false; IsInitialized = false;
try
{
OnFactoryReset();
OnReset?.Invoke(this); OnReset?.Invoke(this);
OnStateChanged?.Invoke(this); OnStateChanged?.Invoke(this);
} }
catch (System.Exception e)
{
Debug.LogError(e);
}
}
/// <inheritdoc cref="Initialize"/> /// <inheritdoc cref="Initialize"/>
protected abstract void OnFactoryInitialize(); protected abstract void OnFactoryInitialize();