Actions and IsInitialized Field Added
This commit is contained in:
parent
49b1bcd578
commit
54168a4a4d
|
@ -1,10 +1,46 @@
|
||||||
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Factory
|
namespace Syntriax.Modules.Factory
|
||||||
{
|
{
|
||||||
public abstract class FactoryBase : MonoBehaviour, IFactory
|
public abstract class FactoryBase : MonoBehaviour, IFactory
|
||||||
{
|
{
|
||||||
public abstract void Initialize();
|
public bool IsInitialized { get; private set; } = false;
|
||||||
public abstract void Reset();
|
|
||||||
|
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
|
namespace Syntriax.Modules.Factory
|
||||||
{
|
{
|
||||||
public interface IFactory
|
public interface IFactory
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// If the <see cref="IFactory"/> is initialized
|
||||||
|
/// </summary>
|
||||||
|
bool IsInitialized { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes the <see cref="IFactory"/>
|
/// Initializes the <see cref="IFactory"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resets the <see cref="IFactory"/>
|
/// Resets the <see cref="IFactory"/>
|
||||||
/// </summary>
|
/// </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