Compare commits
No commits in common. "f25a9b676b0ff7cab3eb15e951472121637f78fa" and "03499d4692cd3a90060b36c4e2c319fd288713a0" have entirely different histories.
f25a9b676b
...
03499d4692
|
@ -4,6 +4,3 @@
|
||||||
[submodule "Trigger"]
|
[submodule "Trigger"]
|
||||||
path = Trigger
|
path = Trigger
|
||||||
url = git@git.syntriax.com:Syntriax/Trigger.git
|
url = git@git.syntriax.com:Syntriax/Trigger.git
|
||||||
[submodule "Factory"]
|
|
||||||
path = Factory
|
|
||||||
url = git@git.syntriax.com:Syntriax/Factory.git
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Syntriax.Modules.Factory;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Config
|
namespace Syntriax.Modules.Movement.Config
|
||||||
|
@ -11,11 +10,29 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
/// <para> Looks for the path specified in the variable <see cref="ResourceDirectoryToDefinitions"/></para>
|
/// <para> Looks for the path specified in the variable <see cref="ResourceDirectoryToDefinitions"/></para>
|
||||||
/// <para> The default path is "Resources/Modules/Syntriax/Movement/Definitions/"</para>
|
/// <para> The default path is "Resources/Modules/Syntriax/Movement/Definitions/"</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public class MovementDefinitionFactory : FactoryBase
|
public class MovementDefinitionFactory : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
internal const string Name = "Movement Definition Factory";
|
||||||
internal const int InitialCapacity = 64;
|
internal const int InitialCapacity = 64;
|
||||||
internal const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
|
internal const string ResourceDirectoryToDefinitions = "Modules/Syntriax/Movement/Definitions/";
|
||||||
|
|
||||||
|
private static MovementDefinitionFactory _instance = null;
|
||||||
|
public static MovementDefinitionFactory Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
GameObject factoriesGO = GameObject.Find("Factories") ?? new GameObject("Factories");
|
||||||
|
_instance = new GameObject(Name).AddComponent<MovementDefinitionFactory>();
|
||||||
|
_instance.transform.SetParent(factoriesGO.transform);
|
||||||
|
DontDestroyOnLoad(factoriesGO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<string, MovementDefinition> _definitions = null;
|
private Dictionary<string, MovementDefinition> _definitions = null;
|
||||||
public Dictionary<string, MovementDefinition> Definitions
|
public Dictionary<string, MovementDefinition> Definitions
|
||||||
{
|
{
|
||||||
|
@ -30,7 +47,7 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
if (FactorySingleton<MovementDefinitionFactory>.Instance == this)
|
if (_instance == this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Destroy(this);
|
Destroy(this);
|
||||||
|
@ -43,7 +60,7 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
/// <para> Automatically loads the definition files specificed path <see cref="ResourceDirectoryToDefinitions"/></para>
|
/// <para> Automatically loads the definition files specificed path <see cref="ResourceDirectoryToDefinitions"/></para>
|
||||||
/// <para> The default is "Resources/Modules/Syntriax/Movement/Definitions/"</para>
|
/// <para> The default is "Resources/Modules/Syntriax/Movement/Definitions/"</para>
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
if (_definitions == null)
|
if (_definitions == null)
|
||||||
_definitions = new Dictionary<string, MovementDefinition>(InitialCapacity);
|
_definitions = new Dictionary<string, MovementDefinition>(InitialCapacity);
|
||||||
|
@ -70,7 +87,7 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// Does not reinitialize, please call <see cref="Initialize"/> to initialize it back
|
/// Does not reinitialize, please call <see cref="Initialize"/> to initialize it back
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public override void Reset() => _definitions?.Clear();
|
public void Reset() => _definitions?.Clear();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a list of <see cref="MovementDefinition"/>s to the factory
|
/// Registers a list of <see cref="MovementDefinition"/>s to the factory
|
||||||
|
@ -101,7 +118,7 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
public void ApplyDefinitionToGameObject(GameObject gameObject, string definitionName)
|
public void ApplyDefinitionToGameObject(GameObject gameObject, string definitionName)
|
||||||
{
|
{
|
||||||
if (!Definitions.ContainsKey(definitionName))
|
if (!Definitions.ContainsKey(definitionName))
|
||||||
throw new System.ArgumentException($"The definition with name \"{definitionName}\" does not exists in the current {nameof(MovementDefinitionFactory)}");
|
throw new System.ArgumentException($"The definition with name \"{definitionName}\" does not exists in the current {Name}");
|
||||||
|
|
||||||
ApplyDefinitionToGameObject(gameObject, Definitions[definitionName]);
|
ApplyDefinitionToGameObject(gameObject, Definitions[definitionName]);
|
||||||
}
|
}
|
||||||
|
@ -115,13 +132,13 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
{
|
{
|
||||||
foreach (MovementConfig movementConfig in definition.MovementConfigs)
|
foreach (MovementConfig movementConfig in definition.MovementConfigs)
|
||||||
{
|
{
|
||||||
IMovement movement = (IMovement)FactorySingleton<MovementFactory>.Instance.AddToGameObject(gameObject, movementConfig.TypeName);
|
IMovement movement = (IMovement)MovementFactory.Instance.AddToGameObject(gameObject, movementConfig.TypeName);
|
||||||
movement.BaseSpeed = movementConfig.BaseSpeed;
|
movement.BaseSpeed = movementConfig.BaseSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (definition.MonoBehaviours != null)
|
if (definition.MonoBehaviours != null)
|
||||||
foreach (string monoBehaviours in definition.MonoBehaviours)
|
foreach (string monoBehaviours in definition.MonoBehaviours)
|
||||||
FactorySingleton<MovementFactory>.Instance.AddToGameObject(gameObject, monoBehaviours);
|
MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,15 +2,32 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Syntriax.Modules.Factory;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Config
|
namespace Syntriax.Modules.Movement.Config
|
||||||
{
|
{
|
||||||
public class MovementFactory : FactoryBase
|
public class MovementFactory : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
private const string Name = "Movement Factory";
|
||||||
private const int InitialCapacity = 64;
|
private const int InitialCapacity = 64;
|
||||||
|
|
||||||
|
private static MovementFactory _instance = null;
|
||||||
|
public static MovementFactory Instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
GameObject factoriesGO = GameObject.Find("Factories") ?? new GameObject("Factories");
|
||||||
|
_instance = new GameObject(Name).AddComponent<MovementFactory>();
|
||||||
|
_instance.transform.SetParent(factoriesGO.transform);
|
||||||
|
DontDestroyOnLoad(factoriesGO);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Dictionary<string, Type> _types = null;
|
private Dictionary<string, Type> _types = null;
|
||||||
public Dictionary<string, Type> Types
|
public Dictionary<string, Type> Types
|
||||||
{
|
{
|
||||||
|
@ -27,13 +44,13 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
if (FactorySingleton<MovementFactory>.Instance == this)
|
if (_instance == this)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Destroy(this);
|
Destroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
if (_types == null)
|
if (_types == null)
|
||||||
_types = new Dictionary<string, Type>(InitialCapacity);
|
_types = new Dictionary<string, Type>(InitialCapacity);
|
||||||
|
@ -44,20 +61,28 @@ namespace Syntriax.Modules.Movement.Config
|
||||||
AddAssemblyToFactory(assembly);
|
AddAssemblyToFactory(assembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Reset() => _types?.Clear();
|
public void Reset() => _types?.Clear();
|
||||||
|
|
||||||
public void AddAssemblyToFactory(Assembly assembly)
|
public void AddAssemblyToFactory(Assembly assembly)
|
||||||
{
|
{
|
||||||
foreach (Type type in assembly.GetTypes().Where(predicate))
|
foreach (Type type in assembly.GetTypes().Where(predicate))
|
||||||
Types.Add(type.FullName, type);
|
Types.Add(GetTypeName(type), type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component AddToGameObject(GameObject gameObject, string name)
|
public Component AddToGameObject(GameObject gameObject, string name)
|
||||||
{
|
{
|
||||||
if (!Types.ContainsKey(name))
|
if (!Types.ContainsKey(name))
|
||||||
throw new ArgumentException($"The key \"{name}\" does not exists in the current {nameof(MovementFactory)}");
|
throw new ArgumentException($"The key \"{name}\" does not exists in the current {Name}");
|
||||||
|
|
||||||
return gameObject.AddComponent(Types[name]);
|
return gameObject.AddComponent(Types[name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetTypeName(Type type)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(type.Namespace))
|
||||||
|
return type.Name;
|
||||||
|
|
||||||
|
return $"{type.Namespace}.{type.Name}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ using UnityEditor;
|
||||||
using UnityEditorInternal;
|
using UnityEditorInternal;
|
||||||
using Syntriax.Modules.Movement.Config;
|
using Syntriax.Modules.Movement.Config;
|
||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.Factory;
|
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement.Editor
|
namespace Syntriax.Modules.Movement.Editor
|
||||||
{
|
{
|
||||||
|
@ -56,12 +55,12 @@ namespace Syntriax.Modules.Movement.Editor
|
||||||
|
|
||||||
GUILayout.Space(10);
|
GUILayout.Space(10);
|
||||||
|
|
||||||
GUILayout.Label("Tip: MovementConfigs->TypeName and MonoBehaviours use the type.FullName value");
|
GUILayout.Label("Tip: MovementConfigs->TypeName and MonoBehaviours have the same naming system");
|
||||||
GUILayout.Label("If under a namespace: \"Namespace.ClassName\"");
|
GUILayout.Label("If under a namespace: \"Namespace.ClassName\"");
|
||||||
GUILayout.Label("If not under a namespace: \"ClassName\"");
|
GUILayout.Label("If not under a namespace: \"ClassName\"");
|
||||||
GUILayout.Space(5);
|
GUILayout.Space(5);
|
||||||
GUILayout.Label($"Tip: Apply these to your GameObjects by using {nameof(MovementDefinitionFactory)} or the {nameof(MovementDefinitionApplier)} component");
|
GUILayout.Label($"Tip: Apply these to your GameObjects by using {nameof(MovementDefinitionFactory)}");
|
||||||
GUILayout.Label($"{nameof(FactorySingleton<MovementDefinitionFactory>)}<{nameof(MovementDefinitionFactory)}>.Instance.ApplyDefinitionToGameObject(\"{movementName.stringValue}\");");
|
GUILayout.Label($"{nameof(MovementDefinitionFactory)}.Instance.ApplyDefinitionToGameObject(\"{movementName.stringValue}\");");
|
||||||
|
|
||||||
if (quickPresetButtonPressed) LoadPresetQuick();
|
if (quickPresetButtonPressed) LoadPresetQuick();
|
||||||
if (longerPresetButtonPressed) LoadPresetLonger();
|
if (longerPresetButtonPressed) LoadPresetLonger();
|
||||||
|
@ -75,12 +74,12 @@ namespace Syntriax.Modules.Movement.Editor
|
||||||
|
|
||||||
movementDefinition.MovementConfigs = new MovementConfig[]
|
movementDefinition.MovementConfigs = new MovementConfig[]
|
||||||
{
|
{
|
||||||
new MovementConfig(typeof(Implementations.GroundMovement1D).FullName, 5f)
|
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
movementDefinition.MonoBehaviours = new string[]
|
movementDefinition.MonoBehaviours = new string[]
|
||||||
{
|
{
|
||||||
typeof(MovementController).FullName
|
MovementFactory.GetTypeName(typeof(MovementController))
|
||||||
};
|
};
|
||||||
|
|
||||||
UpdateSerializedObject();
|
UpdateSerializedObject();
|
||||||
|
@ -92,14 +91,14 @@ namespace Syntriax.Modules.Movement.Editor
|
||||||
|
|
||||||
movementDefinition.MovementConfigs = new MovementConfig[]
|
movementDefinition.MovementConfigs = new MovementConfig[]
|
||||||
{
|
{
|
||||||
new MovementConfig(typeof(Implementations.AirMovement1D).FullName, 5f),
|
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.AirMovement1D)), 5f),
|
||||||
new MovementConfig(typeof(Implementations.GroundMovement1D).FullName, 5f)
|
new MovementConfig(MovementFactory.GetTypeName(typeof(Implementations.GroundMovement1D)), 5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
movementDefinition.MonoBehaviours = new string[]
|
movementDefinition.MonoBehaviours = new string[]
|
||||||
{
|
{
|
||||||
typeof(MovementController).FullName,
|
MovementFactory.GetTypeName(typeof(MovementController)),
|
||||||
typeof(ToggleState.ToggleStateMonoBehaviour).FullName
|
MovementFactory.GetTypeName(typeof(ToggleState.ToggleStateMonoBehaviour))
|
||||||
};
|
};
|
||||||
|
|
||||||
UpdateSerializedObject();
|
UpdateSerializedObject();
|
||||||
|
|
1
Factory
1
Factory
|
@ -1 +0,0 @@
|
||||||
Subproject commit 49b1bcd578aa5d3b6f84750e730d179a950f26c8
|
|
|
@ -1,8 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: 218ba81f028403c4185f629220600c77
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.Factory;
|
|
||||||
using Syntriax.Modules.Movement.Config;
|
using Syntriax.Modules.Movement.Config;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ namespace Syntriax.Modules.Movement
|
||||||
{
|
{
|
||||||
RemoveDefinition();
|
RemoveDefinition();
|
||||||
|
|
||||||
FactorySingleton<MovementDefinitionFactory>.Instance.ApplyDefinitionToGameObject(gameObject, definitionName);
|
MovementDefinitionFactory.Instance.ApplyDefinitionToGameObject(gameObject, definitionName);
|
||||||
appliedDefinitionName = definitionName;
|
appliedDefinitionName = definitionName;
|
||||||
OnMovementDefinitionApplied?.Invoke(gameObject);
|
OnMovementDefinitionApplied?.Invoke(gameObject);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +34,7 @@ namespace Syntriax.Modules.Movement
|
||||||
{
|
{
|
||||||
RemoveDefinition();
|
RemoveDefinition();
|
||||||
|
|
||||||
FactorySingleton<MovementDefinitionFactory>.Instance.ApplyDefinitionToGameObject(gameObject, definition);
|
MovementDefinitionFactory.Instance.ApplyDefinitionToGameObject(gameObject, definition);
|
||||||
appliedDefinitionName = definition.Name;
|
appliedDefinitionName = definition.Name;
|
||||||
OnMovementDefinitionApplied?.Invoke(gameObject);
|
OnMovementDefinitionApplied?.Invoke(gameObject);
|
||||||
}
|
}
|
||||||
|
@ -45,20 +44,20 @@ namespace Syntriax.Modules.Movement
|
||||||
if (string.IsNullOrWhiteSpace(appliedDefinitionName))
|
if (string.IsNullOrWhiteSpace(appliedDefinitionName))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MovementDefinition appliedDefinition = FactorySingleton<MovementDefinitionFactory>.Instance.Definitions[appliedDefinitionName];
|
MovementDefinition appliedDefinition = MovementDefinitionFactory.Instance.Definitions[appliedDefinitionName];
|
||||||
if (appliedDefinition.MovementConfigs == null || appliedDefinition.MonoBehaviours == null)
|
if (appliedDefinition.MovementConfigs == null || appliedDefinition.MonoBehaviours == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (MovementConfig movementConfig in appliedDefinition.MovementConfigs)
|
foreach (MovementConfig movementConfig in appliedDefinition.MovementConfigs)
|
||||||
{
|
{
|
||||||
Type type = FactorySingleton<MovementFactory>.Instance.Types[movementConfig.TypeName];
|
Type type = MovementFactory.Instance.Types[movementConfig.TypeName];
|
||||||
if (TryGetComponent(type, out Component component))
|
if (TryGetComponent(type, out Component component))
|
||||||
Destroy(component);
|
Destroy(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string monoBehaviour in appliedDefinition.MonoBehaviours)
|
foreach (string monoBehaviour in appliedDefinition.MonoBehaviours)
|
||||||
{
|
{
|
||||||
Type type = FactorySingleton<MovementFactory>.Instance.Types[monoBehaviour];
|
Type type = MovementFactory.Instance.Types[monoBehaviour];
|
||||||
if (TryGetComponent(type, out Component component))
|
if (TryGetComponent(type, out Component component))
|
||||||
Destroy(component);
|
Destroy(component);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
## Dependencies
|
## Dependencies
|
||||||
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
|
1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState)
|
||||||
2. [Trigger Module](https://git.syntriax.com/Syntriax/Trigger)
|
2. [Trigger Module](https://git.syntriax.com/Syntriax/Trigger)
|
||||||
3. [Factory Module](https://git.syntriax.com/Syntriax/Factory)
|
|
||||||
|
|
||||||
Make sure to separately clone these modules along with this one too.
|
Make sure to separately clone these modules along with this one too.
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
"name": "Syntriax.Modules.Movement",
|
"name": "Syntriax.Modules.Movement",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
|
"GUID:75469ad4d38634e559750d17036d5f7c",
|
||||||
"GUID:efa9a9bc94c60c74684aafb7428fbf61",
|
"GUID:efa9a9bc94c60c74684aafb7428fbf61",
|
||||||
"GUID:1f5f15fe7e49bdb48a76c5ce9b1c9f2f",
|
"GUID:1f5f15fe7e49bdb48a76c5ce9b1c9f2f"
|
||||||
"GUID:d4c952ed5f59c5a449cda1b0080ed841"
|
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|
Loading…
Reference in New Issue