diff --git a/Config/MovementDefinition.cs b/Config/MovementDefinition.cs index 1c7edec..58bb4b2 100644 --- a/Config/MovementDefinition.cs +++ b/Config/MovementDefinition.cs @@ -6,14 +6,12 @@ namespace Syntriax.Modules.Movement.Config public struct MovementDefinition { public string Name; - public string DefaultVariableMovement; public MovementConfig[] MovementConfigs; public string[] MonoBehaviours; - public MovementDefinition(string name, string defaultVariableMovement, MovementConfig[] movementConfigs, string[] monoBehaviours) + public MovementDefinition(string name, MovementConfig[] movementConfigs, string[] monoBehaviours) { Name = name; - DefaultVariableMovement = defaultVariableMovement; MovementConfigs = movementConfigs; MonoBehaviours = monoBehaviours; } diff --git a/Config/MovementDefinitionFactory.cs b/Config/MovementDefinitionFactory.cs index 5e8a224..c625fd3 100644 --- a/Config/MovementDefinitionFactory.cs +++ b/Config/MovementDefinitionFactory.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Syntriax.Modules.Movement.VariableMovement; using UnityEngine; namespace Syntriax.Modules.Movement.Config @@ -94,13 +93,6 @@ namespace Syntriax.Modules.Movement.Config if (definition.MonoBehaviours != null) foreach (string monoBehaviours in definition.MonoBehaviours) MovementFactory.Instance.AddToGameObject(gameObject, monoBehaviours); - - if (string.IsNullOrEmpty(definition.DefaultVariableMovement)) - return; - - IVariableMovementController variableMovementController = gameObject.GetComponent(); - VMCollection collection = VariableMovementFactory.Instance.Collections[definition.DefaultVariableMovement]; - variableMovementController?.LoadVariableMovementCollection(collection); } #if UNITY_EDITOR diff --git a/Config/VariableMovementFactory.cs b/Config/VariableMovementFactory.cs deleted file mode 100644 index 6914ddd..0000000 --- a/Config/VariableMovementFactory.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using UnityEngine; -using Syntriax.Modules.Movement.VariableMovement; - -namespace Syntriax.Modules.Movement.Config -{ - public class VariableMovementFactory : MonoBehaviour - { - private const string Name = "Variable Movement Factory"; - private const int InitialCapacity = 64; - private const string ResourceDirectoryToCollections = "Modules/Syntriax/Movement/Variable Movement/Collections/"; - - private static VariableMovementFactory _instance = null; - public static VariableMovementFactory Instance - { - get - { - if (_instance == null) - _instance = new GameObject(Name).AddComponent(); - - return _instance; - } - } - - private Dictionary _collections = null; - public Dictionary Collections - { - get - { - if (_collections == null) - Initialize(); - - return _collections; - } - } - - private void Start() - { - if (_instance == this) - return; - - Destroy(this); - } - - public void Initialize() - { - if (_collections == null) - _collections = new Dictionary(InitialCapacity); - - Reset(); - - foreach (TextAsset definitionTextAsset in UnityEngine.Resources.LoadAll(ResourceDirectoryToCollections)) - AddToFactoryWithJSON(definitionTextAsset.text); - } - - public void AddToFactoryWithJSON(string definitionJSONText) - { - VMCollection collectionDefinition = JsonUtility.FromJson(definitionJSONText); - AddCollectionToFactory(collectionDefinition); - } - - public void Reset() => _collections?.Clear(); - - public void AddCollectionsToFactory(List collections) - { - foreach (VMCollection collection in collections) - AddCollectionToFactory(collection); - } - - public void AddCollectionToFactory(VMCollection collection) - { - if (Collections.ContainsKey(collection.Name)) - throw new System.ArgumentException($"{collection.Name} is already in the {Name}"); - - Collections.Add(collection.Name, collection); - } - - // public Component AddToGameObject(GameObject gameObject, string name) - // { - // if (!Collections.ContainsKey(name)) - // throw new ArgumentException($"The key \"{ name }\" does not exists in the current Movement Factory"); - - // return gameObject.AddComponent(Collections[name]); - // } - - public string GetTypeName(Type type) - { - if (string.IsNullOrEmpty(type.Namespace)) - return type.Name; - - return $"{type.Namespace}.{type.Name}"; - } - -#if UNITY_EDITOR - public void SaveCollection(VMCollection collection) - { - string jsonText = JsonUtility.ToJson(collection, true); - string path = $"Assets/Resources/{ResourceDirectoryToCollections}{collection.Name}.json"; - System.IO.File.WriteAllText(path, jsonText); - } -#endif - } -} diff --git a/Config/VariableMovementFactory.cs.meta b/Config/VariableMovementFactory.cs.meta deleted file mode 100644 index 4e279d8..0000000 --- a/Config/VariableMovementFactory.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 514a385e4a5f87b47ae0f508bc253fb9 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement.meta b/VariableMovement.meta deleted file mode 100644 index a3e663c..0000000 --- a/VariableMovement.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 726dbb7aaeb452e42b1faf1318513cdb -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/IVariableMovement.cs b/VariableMovement/IVariableMovement.cs deleted file mode 100644 index 30bd31c..0000000 --- a/VariableMovement/IVariableMovement.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Syntriax.Modules.Movement.VariableMovement -{ - public interface IVariableMovement - { - VMAsset Asset { get; set; } - } -} diff --git a/VariableMovement/IVariableMovement.cs.meta b/VariableMovement/IVariableMovement.cs.meta deleted file mode 100644 index e67271f..0000000 --- a/VariableMovement/IVariableMovement.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6cdf8a548c241e0419fcf7e95c760cae -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/IVariableMovementController.cs b/VariableMovement/IVariableMovementController.cs deleted file mode 100644 index d4e4d7e..0000000 --- a/VariableMovement/IVariableMovementController.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using UnityEngine.InputSystem; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - public interface IVariableMovementController - { - IVariableMovement ActiveVariableMovement { get; } - Action OnVariableMovementChanged { get; set; } - IInputActionCollection InputActionCollection { get; set; } - - void LoadVariableMovementCollection(VMCollection collection); - } -} diff --git a/VariableMovement/IVariableMovementController.cs.meta b/VariableMovement/IVariableMovementController.cs.meta deleted file mode 100644 index 1517b91..0000000 --- a/VariableMovement/IVariableMovementController.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8626f2dd751462548adce79ccb84d6d3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/IVariableMovementWithState.cs b/VariableMovement/IVariableMovementWithState.cs deleted file mode 100644 index af5df89..0000000 --- a/VariableMovement/IVariableMovementWithState.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using UnityEngine.InputSystem; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - public interface IVariableMovementWithState : IVariableMovement - { - bool Enabled { get; set; } - Action OnToggleStateChanged { get; set; } - IInputActionCollection InputCollection { set; } - } -} diff --git a/VariableMovement/IVariableMovementWithState.cs.meta b/VariableMovement/IVariableMovementWithState.cs.meta deleted file mode 100644 index 1d335fc..0000000 --- a/VariableMovement/IVariableMovementWithState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: c4e5bc603a4ef1342abf1e987cfced7f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/ScriptableObjects.meta b/VariableMovement/ScriptableObjects.meta deleted file mode 100644 index c215cb7..0000000 --- a/VariableMovement/ScriptableObjects.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 63a9b9d234afa1d4d81a6f018393c057 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/ScriptableObjects/VMAssetSO.cs b/VariableMovement/ScriptableObjects/VMAssetSO.cs deleted file mode 100644 index a69b618..0000000 --- a/VariableMovement/ScriptableObjects/VMAssetSO.cs +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - [CreateAssetMenu(fileName = "VMAsset", menuName = "Syntriax/Modules/Movement/Variable Movement/Asset", order = 0)] - public class VMAssetSO : ScriptableObject - { - public VMAsset asset; - } -} diff --git a/VariableMovement/ScriptableObjects/VMAssetSO.cs.meta b/VariableMovement/ScriptableObjects/VMAssetSO.cs.meta deleted file mode 100644 index 00ca2ca..0000000 --- a/VariableMovement/ScriptableObjects/VMAssetSO.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 675d01134857a5b4aa8278985b7d2c09 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/ScriptableObjects/VMCollectionSO.cs b/VariableMovement/ScriptableObjects/VMCollectionSO.cs deleted file mode 100644 index 18eadf2..0000000 --- a/VariableMovement/ScriptableObjects/VMCollectionSO.cs +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - [CreateAssetMenu(fileName = "VMCollection", menuName = "Syntriax/Modules/Movement/Variable Movement/Collection", order = 0)] - public class VMCollectionSO : ScriptableObject - { - public VMCollection collection; - } -} diff --git a/VariableMovement/ScriptableObjects/VMCollectionSO.cs.meta b/VariableMovement/ScriptableObjects/VMCollectionSO.cs.meta deleted file mode 100644 index 5e72105..0000000 --- a/VariableMovement/ScriptableObjects/VMCollectionSO.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b6d52a12481917c4b877c026fa81dfef -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/VMAsset.cs b/VariableMovement/VMAsset.cs deleted file mode 100644 index 59aa652..0000000 --- a/VariableMovement/VMAsset.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - [Serializable] - public struct VMAsset - { - public string Name; - public float Multiplier; - public string ActionReference; - - public VMAsset(string name, float multiplier, string actionReference) - { - Name = name; - Multiplier = multiplier; - ActionReference = actionReference; - } - } -} diff --git a/VariableMovement/VMAsset.cs.meta b/VariableMovement/VMAsset.cs.meta deleted file mode 100644 index 190d51c..0000000 --- a/VariableMovement/VMAsset.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 35f90754856e0cf43a33a1a6bc5e0423 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/VMCollection.cs b/VariableMovement/VMCollection.cs deleted file mode 100644 index 435ff46..0000000 --- a/VariableMovement/VMCollection.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - [Serializable] - public struct VMCollection - { - public string Name; - public VMAsset DefaultAsset; - public VMAsset[] VMAssets; - - public VMCollection(string name, VMAsset defaultAsset, VMAsset[] vMAssets) - { - Name = name; - DefaultAsset = defaultAsset; - VMAssets = vMAssets; - } - } -} diff --git a/VariableMovement/VMCollection.cs.meta b/VariableMovement/VMCollection.cs.meta deleted file mode 100644 index 8ae96ef..0000000 --- a/VariableMovement/VMCollection.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 6c9addcc3980a2948b5c2e493f8f1642 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/VariableMovement.cs b/VariableMovement/VariableMovement.cs deleted file mode 100644 index 49b3cc3..0000000 --- a/VariableMovement/VariableMovement.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Syntriax.Modules.Movement.VariableMovement -{ - public class VariableMovement : IVariableMovement - { - public VMAsset Asset { get; set; } - - public VariableMovement() { } - public VariableMovement(VMAsset asset) - => Asset = asset; - } -} diff --git a/VariableMovement/VariableMovement.cs.meta b/VariableMovement/VariableMovement.cs.meta deleted file mode 100644 index 02f0e85..0000000 --- a/VariableMovement/VariableMovement.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9fa3a5e4edf40ce42a96a32da76de626 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/VariableMovementController.cs b/VariableMovement/VariableMovementController.cs deleted file mode 100644 index 7fb676b..0000000 --- a/VariableMovement/VariableMovementController.cs +++ /dev/null @@ -1,114 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.InputSystem; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - public class VariableMovementController : MonoBehaviour, IVariableMovementController - { - public Action OnVariableMovementChanged { get; set; } = null; - private IInputActionCollection _inputActionCollection = null; - public IInputActionCollection InputActionCollection - { - get => _inputActionCollection; - set - { - _inputActionCollection = value; - - foreach (IVariableMovementWithState variableMovement in variableMovementsWithState) - variableMovement.InputCollection = value; - } - } - private IVariableMovement _activeVariableMovement = null; - public IVariableMovement ActiveVariableMovement - { - get => _activeVariableMovement; - protected set - { - _activeVariableMovement = value; - OnVariableMovementChanged.Invoke(value); - - if (movementController != null) - SetMultiplierToActiveMovement(movementController.ActiveMovement); - } - } - - protected bool isSet = false; - protected IMovementController movementController = null; - protected IVariableMovement defaultVariableMovement = null; - protected List variableMovementsWithState = null; - protected VMCollection collection; - - protected virtual void Awake() - { - defaultVariableMovement = new VariableMovement(); - variableMovementsWithState = new List(16); - } - - protected virtual void Start() - { - movementController = GetComponent(); - movementController.OnMovementActivated += SetMultiplierToActiveMovement; - movementController.OnMovementDeactivated += ResetMultiplierToDefault; - } - - private void ResetMultiplierToDefault(IMovement currentMovement) - { - if (!isSet) - return; - - currentMovement.MovementMultiplier = defaultVariableMovement.Asset.Multiplier; - } - - protected void SetMultiplierToActiveMovement(IMovement currentMovement) - { - if (!isSet) - return; - - currentMovement.MovementMultiplier = ActiveVariableMovement.Asset.Multiplier; - - } - - public void LoadVariableMovementCollection(VMCollection collection) - { - this.collection = collection; - isSet = true; - - UnsubscribeFromMovements(); - - variableMovementsWithState.Clear(); - foreach (VMAsset asset in collection.VMAssets) - variableMovementsWithState.Add(new VariableMovementWithState(asset, InputActionCollection)); - defaultVariableMovement.Asset = collection.DefaultAsset; - - SubscribeToMovements(); - UpdateActiveVariableMovement(); - } - - protected virtual void SubscribeToMovements() - { - foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState) - variableMovementWithState.OnToggleStateChanged += VariableMovementStateListener; - } - - protected virtual void UnsubscribeFromMovements() - { - foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState) - variableMovementWithState.OnToggleStateChanged -= VariableMovementStateListener; - } - - private void VariableMovementStateListener(bool arg0) => UpdateActiveVariableMovement(); - protected virtual void UpdateActiveVariableMovement() - { - foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState) - if (variableMovementWithState.Enabled) - { - ActiveVariableMovement = variableMovementWithState; - return; - } - - ActiveVariableMovement = defaultVariableMovement; - } - } -} diff --git a/VariableMovement/VariableMovementController.cs.meta b/VariableMovement/VariableMovementController.cs.meta deleted file mode 100644 index 7334b1e..0000000 --- a/VariableMovement/VariableMovementController.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9c54e2868362dbe4eab92c16ee11fc42 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/VariableMovement/VariableMovementWithState.cs b/VariableMovement/VariableMovementWithState.cs deleted file mode 100644 index 490c7b8..0000000 --- a/VariableMovement/VariableMovementWithState.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using UnityEngine.InputSystem; - -namespace Syntriax.Modules.Movement.VariableMovement -{ - public class VariableMovementWithState : IVariableMovementWithState - { - public Action OnToggleStateChanged { get; set; } = null; - private bool _enabled = false; - public bool Enabled - { - get => _enabled; - set - { - bool isNewValue = _enabled != value; - - _enabled = value; - - if (isNewValue) - OnToggleStateChanged.Invoke(value); - } - } - private VMAsset _asset; - public VMAsset Asset - { - get => _asset; - set - { - UpdateBindings(); - - _asset = value; - - Enabled = false; - } - } - - private IInputActionCollection _inputCollection = null; - public IInputActionCollection InputCollection - { - set - { - if (_inputCollection == value) - return; - - _inputCollection = value; - UpdateBindings(); - } - } - - protected InputAction actionReference = null; - - public VariableMovementWithState(VMAsset asset, IInputActionCollection inputCollection) - { - InputCollection = inputCollection; - Asset = asset; - } - - protected void Cancelled(InputAction.CallbackContext obj) => Enabled = false; - protected void Performed(InputAction.CallbackContext obj) => Enabled = true; - - protected void UpdateBindings() - { - if (actionReference != null) - { - actionReference.performed -= Performed; - actionReference.canceled -= Cancelled; - } - - if (_inputCollection != null) - foreach (InputAction action in _inputCollection) - if (action.name == Asset.ActionReference) - { - actionReference = action; - actionReference.performed += Performed; - actionReference.canceled += Cancelled; - break; - } - } - } -} diff --git a/VariableMovement/VariableMovementWithState.cs.meta b/VariableMovement/VariableMovementWithState.cs.meta deleted file mode 100644 index 3624c65..0000000 --- a/VariableMovement/VariableMovementWithState.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 95216561eb395f54596b439538c1c691 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: