From 619aba0a2e7730751d7d49dfd4f7203d0a51d44d Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 5 Mar 2022 13:47:41 +0300 Subject: [PATCH] Factories Added --- ColliderCheck/ColliderCheckFactory.cs | 11 +++ ColliderCheck/ColliderCheckFactory.cs.meta | 11 +++ MovementFactory.cs | 10 ++ MovementFactory.cs.meta | 11 +++ SpecialAction/Factories.meta | 8 ++ .../SpecialActionDeactivateFactory.cs | 10 ++ .../SpecialActionDeactivateFactory.cs.meta | 11 +++ SpecialAction/SpecialActionFactory.cs | 10 ++ SpecialAction/SpecialActionFactory.cs.meta | 11 +++ TypeFactoryBase.cs | 93 +++++++++++++++++++ TypeFactoryBase.cs.meta | 11 +++ VariableMovement/Factories.meta | 8 ++ .../Factories/VariableMovementAssetFactory.cs | 10 ++ .../VariableMovementAssetFactory.cs.meta | 11 +++ .../VariableMovementCollectionFactory.cs | 10 ++ .../VariableMovementCollectionFactory.cs.meta | 11 +++ .../VariableMovementControllerFactory.cs | 10 ++ .../VariableMovementControllerFactory.cs.meta | 11 +++ .../Factories/VariableMovementFactory.cs | 10 ++ .../Factories/VariableMovementFactory.cs.meta | 11 +++ .../VariableMovementBehaviourApplier.cs | 24 +++++ .../VariableMovementBehaviourApplier.cs.meta | 11 +++ 22 files changed, 324 insertions(+) create mode 100644 ColliderCheck/ColliderCheckFactory.cs create mode 100644 ColliderCheck/ColliderCheckFactory.cs.meta create mode 100644 MovementFactory.cs create mode 100644 MovementFactory.cs.meta create mode 100644 SpecialAction/Factories.meta create mode 100644 SpecialAction/SpecialActionDeactivateFactory.cs create mode 100644 SpecialAction/SpecialActionDeactivateFactory.cs.meta create mode 100644 SpecialAction/SpecialActionFactory.cs create mode 100644 SpecialAction/SpecialActionFactory.cs.meta create mode 100644 TypeFactoryBase.cs create mode 100644 TypeFactoryBase.cs.meta create mode 100644 VariableMovement/Factories.meta create mode 100644 VariableMovement/Factories/VariableMovementAssetFactory.cs create mode 100644 VariableMovement/Factories/VariableMovementAssetFactory.cs.meta create mode 100644 VariableMovement/Factories/VariableMovementCollectionFactory.cs create mode 100644 VariableMovement/Factories/VariableMovementCollectionFactory.cs.meta create mode 100644 VariableMovement/Factories/VariableMovementControllerFactory.cs create mode 100644 VariableMovement/Factories/VariableMovementControllerFactory.cs.meta create mode 100644 VariableMovement/Factories/VariableMovementFactory.cs create mode 100644 VariableMovement/Factories/VariableMovementFactory.cs.meta create mode 100644 VariableMovement/VariableMovementBehaviourApplier.cs create mode 100644 VariableMovement/VariableMovementBehaviourApplier.cs.meta diff --git a/ColliderCheck/ColliderCheckFactory.cs b/ColliderCheck/ColliderCheckFactory.cs new file mode 100644 index 0000000..39f73e2 --- /dev/null +++ b/ColliderCheck/ColliderCheckFactory.cs @@ -0,0 +1,11 @@ +using System; +using System.Linq; +using UnityEngine; + +namespace Syntriax.Modules.Movement.ColliderCheck +{ + public class ColliderCheckFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/ColliderCheck/ColliderCheckFactory.cs.meta b/ColliderCheck/ColliderCheckFactory.cs.meta new file mode 100644 index 0000000..b7a7785 --- /dev/null +++ b/ColliderCheck/ColliderCheckFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b1da221e5cee86a429230fca11bdf8dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/MovementFactory.cs b/MovementFactory.cs new file mode 100644 index 0000000..b5f8c1f --- /dev/null +++ b/MovementFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement +{ + public class MovementFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/MovementFactory.cs.meta b/MovementFactory.cs.meta new file mode 100644 index 0000000..505110e --- /dev/null +++ b/MovementFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a549f3c5b33e60042b996e8988c4dfb6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SpecialAction/Factories.meta b/SpecialAction/Factories.meta new file mode 100644 index 0000000..1673a31 --- /dev/null +++ b/SpecialAction/Factories.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f563d60029ac74b4f960a1fb0f28ac5c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SpecialAction/SpecialActionDeactivateFactory.cs b/SpecialAction/SpecialActionDeactivateFactory.cs new file mode 100644 index 0000000..6095ce8 --- /dev/null +++ b/SpecialAction/SpecialActionDeactivateFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.SpecialAction +{ + public class SpecialActionDeactivateFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/SpecialAction/SpecialActionDeactivateFactory.cs.meta b/SpecialAction/SpecialActionDeactivateFactory.cs.meta new file mode 100644 index 0000000..eb1628b --- /dev/null +++ b/SpecialAction/SpecialActionDeactivateFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f47f89e40f357be429015f81d7e8776d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/SpecialAction/SpecialActionFactory.cs b/SpecialAction/SpecialActionFactory.cs new file mode 100644 index 0000000..d95e3a3 --- /dev/null +++ b/SpecialAction/SpecialActionFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.SpecialAction +{ + public class SpecialActionActivateFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/SpecialAction/SpecialActionFactory.cs.meta b/SpecialAction/SpecialActionFactory.cs.meta new file mode 100644 index 0000000..d496937 --- /dev/null +++ b/SpecialAction/SpecialActionFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cb0ba82e296c6144ca97136f508e6aa5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TypeFactoryBase.cs b/TypeFactoryBase.cs new file mode 100644 index 0000000..2879321 --- /dev/null +++ b/TypeFactoryBase.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using UnityEngine; + +namespace Syntriax.Modules.Movement +{ + public abstract class TypeFactoryBaseMonoBehaviour : MonoBehaviour + where T : TypeFactoryBaseMonoBehaviour + where T2 : class + { + protected abstract int InitialCapacity { get; } + + private Func predicate => type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(MonoBehaviour)) && type.GetInterfaces().Contains(typeof(T2)); + private string factoryName => typeof(T).Name; + private static TypeFactoryBaseMonoBehaviour _instance = null; + public static TypeFactoryBaseMonoBehaviour Instance + { + get + { + if (_instance == null) + { + GameObject newGameObject = new GameObject(); + TypeFactoryBaseMonoBehaviour typeFactoryBase = newGameObject.AddComponent(); + newGameObject.name = typeFactoryBase.factoryName; + _instance = typeFactoryBase; + } + + return _instance; + } + } + + private Dictionary _types = null; + public Dictionary Types + { + get + { + Initialize(); + return _types; + } + } + + public void Initialize() + { + if (_types != null) + return; + + _types = new Dictionary(InitialCapacity); + + foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies()) + foreach (Type type in assembly.GetTypes().Where(predicate)) + _types.Add(GetTypeClassName(type), type); + } + + + public virtual void Start() + { + if (_instance != this) + Destroy(this); + } + + public void AddTypes(List<(string ClassName, Type TypeReference)> types) + { + foreach (var pair in types) + AddType(pair.ClassName, pair.TypeReference); + } + + public void AddType(string className, Type type) + { + if (Types.ContainsKey(className)) + throw new ArgumentException($"Component with the key \"{ className }\" already been loaded!"); + + Types.Add(className, type); + } + + public void LoadTypesFromAssembly(Assembly assembly) + { + foreach (Type type in assembly.GetTypes().Where(predicate)) + AddType(GetTypeClassName(type), type); + } + + public T2 AddComponentToGameObject(GameObject gameObject, string className) + { + if (!Types.ContainsKey(className)) + throw new ArgumentException($"Component with the key \"{ className }\" does not exist!"); + + return gameObject.AddComponent(Types[className]) as T2; + } + + private static string GetTypeClassName(Type type) => $"{ type.Namespace }.{ type.Name }"; + } +} diff --git a/TypeFactoryBase.cs.meta b/TypeFactoryBase.cs.meta new file mode 100644 index 0000000..2250054 --- /dev/null +++ b/TypeFactoryBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ede07d45859817e489065dd95be5428a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/Factories.meta b/VariableMovement/Factories.meta new file mode 100644 index 0000000..a4d0a3f --- /dev/null +++ b/VariableMovement/Factories.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bb29c5d8308d0b5469f8761266612fe5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/Factories/VariableMovementAssetFactory.cs b/VariableMovement/Factories/VariableMovementAssetFactory.cs new file mode 100644 index 0000000..907bb36 --- /dev/null +++ b/VariableMovement/Factories/VariableMovementAssetFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.VariableMovement +{ + public class VariableMovementAssetFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/VariableMovement/Factories/VariableMovementAssetFactory.cs.meta b/VariableMovement/Factories/VariableMovementAssetFactory.cs.meta new file mode 100644 index 0000000..4df0a5e --- /dev/null +++ b/VariableMovement/Factories/VariableMovementAssetFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca4cae9b447933d4380cb3664509b0dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/Factories/VariableMovementCollectionFactory.cs b/VariableMovement/Factories/VariableMovementCollectionFactory.cs new file mode 100644 index 0000000..b3bb1f0 --- /dev/null +++ b/VariableMovement/Factories/VariableMovementCollectionFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.VariableMovement +{ + public class VariableMovementCollectionFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/VariableMovement/Factories/VariableMovementCollectionFactory.cs.meta b/VariableMovement/Factories/VariableMovementCollectionFactory.cs.meta new file mode 100644 index 0000000..2a9bdba --- /dev/null +++ b/VariableMovement/Factories/VariableMovementCollectionFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bfc49ded5329db443b2ae57e61ad77a4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/Factories/VariableMovementControllerFactory.cs b/VariableMovement/Factories/VariableMovementControllerFactory.cs new file mode 100644 index 0000000..18320bf --- /dev/null +++ b/VariableMovement/Factories/VariableMovementControllerFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.VariableMovement +{ + public class VariableMovementControllerFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/VariableMovement/Factories/VariableMovementControllerFactory.cs.meta b/VariableMovement/Factories/VariableMovementControllerFactory.cs.meta new file mode 100644 index 0000000..b13f51b --- /dev/null +++ b/VariableMovement/Factories/VariableMovementControllerFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a76af33a21338f49bec92f17a6d6aca +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/Factories/VariableMovementFactory.cs b/VariableMovement/Factories/VariableMovementFactory.cs new file mode 100644 index 0000000..a2ef4fb --- /dev/null +++ b/VariableMovement/Factories/VariableMovementFactory.cs @@ -0,0 +1,10 @@ +using System; +using System.Linq; + +namespace Syntriax.Modules.Movement.VariableMovement +{ + public class VariableMovementFactory : TypeFactoryBaseMonoBehaviour + { + protected override int InitialCapacity => 8; + } +} diff --git a/VariableMovement/Factories/VariableMovementFactory.cs.meta b/VariableMovement/Factories/VariableMovementFactory.cs.meta new file mode 100644 index 0000000..b5b2734 --- /dev/null +++ b/VariableMovement/Factories/VariableMovementFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c96b25d959676ca4f9246e903fd2a928 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/VariableMovement/VariableMovementBehaviourApplier.cs b/VariableMovement/VariableMovementBehaviourApplier.cs new file mode 100644 index 0000000..714503f --- /dev/null +++ b/VariableMovement/VariableMovementBehaviourApplier.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace Syntriax.Modules.Movement.VariableMovement +{ + public class VariableMovementBehaviourApplier : MonoBehaviour + { + private List movements = new List(); + private IVariableMovementController variableMovementController = null; + + private void Start() + { + movements = GetComponents().ToList(); + variableMovementController = GetComponent(); + } + + private void Update() + { + foreach (var movement in movements) + movement.MovementMultiplier = variableMovementController.CurrentVariableMovement.VariableMovementAsset.MovementMultiplier; + } + } +} diff --git a/VariableMovement/VariableMovementBehaviourApplier.cs.meta b/VariableMovement/VariableMovementBehaviourApplier.cs.meta new file mode 100644 index 0000000..91f4d26 --- /dev/null +++ b/VariableMovement/VariableMovementBehaviourApplier.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 47f9c34946b1c4a4d9b31dc2f1a6e315 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: