From 7565da4a9c4356b77572818f3ecc018476b88c41 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 21 Nov 2022 13:33:46 +0300 Subject: [PATCH] First Commit --- FactoryBase.cs | 10 ++++++++++ FactoryBase.cs.meta | 11 +++++++++++ FactorySingleton.cs | 28 ++++++++++++++++++++++++++++ FactorySingleton.cs.meta | 11 +++++++++++ IFactory.cs | 8 ++++++++ IFactory.cs.meta | 11 +++++++++++ README.md.meta | 7 +++++++ 7 files changed, 86 insertions(+) create mode 100644 FactoryBase.cs create mode 100644 FactoryBase.cs.meta create mode 100644 FactorySingleton.cs create mode 100644 FactorySingleton.cs.meta create mode 100644 IFactory.cs create mode 100644 IFactory.cs.meta create mode 100644 README.md.meta 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: