using System; using UnityEngine; namespace Syntriax.Modules.Factory { public abstract class FactoryBase : MonoBehaviour, IFactory { 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; IsInitialized = true; try { OnFactoryInitialize(); OnInitialized?.Invoke(this); OnStateChanged?.Invoke(this); } catch (System.Exception e) { Debug.LogError(e); Reset(); } } public void Reset() { if (!IsInitialized) return; IsInitialized = false; try { OnFactoryReset(); OnReset?.Invoke(this); OnStateChanged?.Invoke(this); } catch (System.Exception e) { Debug.LogError(e); } } /// protected abstract void OnFactoryInitialize(); /// protected abstract void OnFactoryReset(); } }