Factory/FactoryBase.cs

47 lines
1.1 KiB
C#

using System;
using UnityEngine;
namespace Syntriax.Modules.Factory
{
public abstract class FactoryBase : MonoBehaviour, IFactory
{
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();
}
}