Actions and IsInitialized Field Added
This commit is contained in:
parent
49b1bcd578
commit
54168a4a4d
|
@ -1,10 +1,46 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Factory
|
||||
{
|
||||
public abstract class FactoryBase : MonoBehaviour, IFactory
|
||||
{
|
||||
public abstract void Initialize();
|
||||
public abstract void Reset();
|
||||
public bool IsInitialized { get; private set; } = false;
|
||||
|
||||
public Action<IFactory> OnInitialized { get; set; } = null;
|
||||
public Action<IFactory> OnReset { get; set; } = null;
|
||||
public Action<IFactory> OnStateChanged { get; set; } = null;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (IsInitialized)
|
||||
return;
|
||||
|
||||
OnFactoryInitialize();
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
OnInitialized?.Invoke(this);
|
||||
OnStateChanged?.Invoke(this);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
return;
|
||||
|
||||
OnFactoryReset();
|
||||
|
||||
IsInitialized = false;
|
||||
|
||||
OnReset?.Invoke(this);
|
||||
OnStateChanged?.Invoke(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="Initialize"/>
|
||||
protected abstract void OnFactoryInitialize();
|
||||
|
||||
/// <inheritdoc cref="Reset"/>
|
||||
protected abstract void OnFactoryReset();
|
||||
}
|
||||
}
|
||||
|
|
15
IFactory.cs
15
IFactory.cs
|
@ -1,15 +1,26 @@
|
|||
using System;
|
||||
|
||||
namespace Syntriax.Modules.Factory
|
||||
{
|
||||
public interface IFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// If the <see cref="IFactory"/> is initialized
|
||||
/// </summary>
|
||||
bool IsInitialized { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="IFactory"/>
|
||||
/// </summary>
|
||||
public void Initialize();
|
||||
void Initialize();
|
||||
|
||||
/// <summary>
|
||||
/// Resets the <see cref="IFactory"/>
|
||||
/// </summary>
|
||||
public void Reset();
|
||||
void Reset();
|
||||
|
||||
Action<IFactory> OnInitialized { get; set; }
|
||||
Action<IFactory> OnReset { get; set; }
|
||||
Action<IFactory> OnStateChanged { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue