From 54168a4a4d0ee483a9c11985e30a32001f248769 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 21 Nov 2022 21:51:23 +0300 Subject: [PATCH] Actions and IsInitialized Field Added --- FactoryBase.cs | 40 ++++++++++++++++++++++++++++++++++++++-- IFactory.cs | 15 +++++++++++++-- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/FactoryBase.cs b/FactoryBase.cs index 5a172ff..984a94c 100644 --- a/FactoryBase.cs +++ b/FactoryBase.cs @@ -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 OnInitialized { get; set; } = null; + public Action OnReset { get; set; } = null; + public Action 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); + } + + /// + protected abstract void OnFactoryInitialize(); + + /// + protected abstract void OnFactoryReset(); } } diff --git a/IFactory.cs b/IFactory.cs index ce47ebe..f76eb57 100644 --- a/IFactory.cs +++ b/IFactory.cs @@ -1,15 +1,26 @@ +using System; + namespace Syntriax.Modules.Factory { public interface IFactory { + /// + /// If the is initialized + /// + bool IsInitialized { get; } + /// /// Initializes the /// - public void Initialize(); + void Initialize(); /// /// Resets the /// - public void Reset(); + void Reset(); + + Action OnInitialized { get; set; } + Action OnReset { get; set; } + Action OnStateChanged { get; set; } } }