using UnityEngine; namespace Syntriax.Modules.Factory { public abstract class FactorySingleton : MonoBehaviour where T : FactoryBase { public const string ParentName = "Factories"; private static T _instance = null; public static T Instance { get { if (_instance == null) { GameObject factoriesGO = GameObject.Find(ParentName) ?? new GameObject(ParentName); _instance = new GameObject(typeof(T).Name).AddComponent(); _instance.transform.SetParent(factoriesGO.transform); DontDestroyOnLoad(factoriesGO); } return _instance; } } } }