Factories Added
This commit is contained in:
parent
c7418eb578
commit
619aba0a2e
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement.ColliderCheck
|
||||
{
|
||||
public class ColliderCheckFactory : TypeFactoryBaseMonoBehaviour<ColliderCheckFactory, IColliderCheck>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b1da221e5cee86a429230fca11bdf8dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
public class MovementFactory : TypeFactoryBaseMonoBehaviour<MovementFactory, IMovement>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a549f3c5b33e60042b996e8988c4dfb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f563d60029ac74b4f960a1fb0f28ac5c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.SpecialAction
|
||||
{
|
||||
public class SpecialActionDeactivateFactory : TypeFactoryBaseMonoBehaviour<SpecialActionDeactivateFactory, ISpecialActionDeactivate>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f47f89e40f357be429015f81d7e8776d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.SpecialAction
|
||||
{
|
||||
public class SpecialActionActivateFactory : TypeFactoryBaseMonoBehaviour<SpecialActionActivateFactory, ISpecialActionActivate>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb0ba82e296c6144ca97136f508e6aa5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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<T, T2> : MonoBehaviour
|
||||
where T : TypeFactoryBaseMonoBehaviour<T, T2>
|
||||
where T2 : class
|
||||
{
|
||||
protected abstract int InitialCapacity { get; }
|
||||
|
||||
private Func<Type, bool> predicate => type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(MonoBehaviour)) && type.GetInterfaces().Contains(typeof(T2));
|
||||
private string factoryName => typeof(T).Name;
|
||||
private static TypeFactoryBaseMonoBehaviour<T, T2> _instance = null;
|
||||
public static TypeFactoryBaseMonoBehaviour<T, T2> Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
GameObject newGameObject = new GameObject();
|
||||
TypeFactoryBaseMonoBehaviour<T, T2> typeFactoryBase = newGameObject.AddComponent<T>();
|
||||
newGameObject.name = typeFactoryBase.factoryName;
|
||||
_instance = typeFactoryBase;
|
||||
}
|
||||
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<string, Type> _types = null;
|
||||
public Dictionary<string, Type> Types
|
||||
{
|
||||
get
|
||||
{
|
||||
Initialize();
|
||||
return _types;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (_types != null)
|
||||
return;
|
||||
|
||||
_types = new Dictionary<string, Type>(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 }";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ede07d45859817e489065dd95be5428a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb29c5d8308d0b5469f8761266612fe5
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
public class VariableMovementAssetFactory : TypeFactoryBaseMonoBehaviour<VariableMovementAssetFactory, IVariableMovementAsset>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ca4cae9b447933d4380cb3664509b0dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
public class VariableMovementCollectionFactory : TypeFactoryBaseMonoBehaviour<VariableMovementCollectionFactory, IVariableMovementCollection>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bfc49ded5329db443b2ae57e61ad77a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
public class VariableMovementControllerFactory : TypeFactoryBaseMonoBehaviour<VariableMovementControllerFactory, IVariableMovementController>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0a76af33a21338f49bec92f17a6d6aca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
public class VariableMovementFactory : TypeFactoryBaseMonoBehaviour<VariableMovementFactory, IVariableMovement>
|
||||
{
|
||||
protected override int InitialCapacity => 8;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c96b25d959676ca4f9246e903fd2a928
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
public class VariableMovementBehaviourApplier : MonoBehaviour
|
||||
{
|
||||
private List<IMovement> movements = new List<IMovement>();
|
||||
private IVariableMovementController variableMovementController = null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
movements = GetComponents<IMovement>().ToList();
|
||||
variableMovementController = GetComponent<IVariableMovementController>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
foreach (var movement in movements)
|
||||
movement.MovementMultiplier = variableMovementController.CurrentVariableMovement.VariableMovementAsset.MovementMultiplier;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 47f9c34946b1c4a4d9b31dc2f1a6e315
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue