Actions and IsInitialized Field Added

This commit is contained in:
Syntriax 2022-11-21 21:51:23 +03:00
parent 49b1bcd578
commit 54168a4a4d
2 changed files with 51 additions and 4 deletions

View File

@ -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();
}
}

View File

@ -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; }
}
}