diff --git a/FactoryBase.cs b/FactoryBase.cs new file mode 100644 index 0000000..5a172ff --- /dev/null +++ b/FactoryBase.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace Syntriax.Modules.Factory +{ + public abstract class FactoryBase : MonoBehaviour, IFactory + { + public abstract void Initialize(); + public abstract void Reset(); + } +} diff --git a/FactoryBase.cs.meta b/FactoryBase.cs.meta new file mode 100644 index 0000000..530233b --- /dev/null +++ b/FactoryBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f03dc034a54c734448dde62aa338c24e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/FactorySingleton.cs b/FactorySingleton.cs new file mode 100644 index 0000000..60c3b12 --- /dev/null +++ b/FactorySingleton.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace Syntriax.Modules.Factory +{ + public abstract class FactorySingleton : MonoBehaviour, IFactory where T : Component, IFactory + { + 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(nameof(T)).AddComponent(); + _instance.transform.SetParent(factoriesGO.transform); + DontDestroyOnLoad(factoriesGO); + } + + return _instance; + } + } + + public void Initialize() => Instance.Initialize(); + public void Reset() => Instance.Reset(); + } +} diff --git a/FactorySingleton.cs.meta b/FactorySingleton.cs.meta new file mode 100644 index 0000000..c72d01c --- /dev/null +++ b/FactorySingleton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3541837e6dc3675418eaa6408d8c81cb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/IFactory.cs b/IFactory.cs new file mode 100644 index 0000000..6a2360c --- /dev/null +++ b/IFactory.cs @@ -0,0 +1,8 @@ +namespace Syntriax.Modules.Factory +{ + public interface IFactory + { + public void Initialize(); + public void Reset(); + } +} diff --git a/IFactory.cs.meta b/IFactory.cs.meta new file mode 100644 index 0000000..2a633ce --- /dev/null +++ b/IFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ae08bf6242ccc1941839a7c16f7037be +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..cad005e --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f53b7b4487fd29d429404199725b6781 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: