From 57790c4598e5610094f7c474c298d3b8178f5117 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sun, 18 Dec 2022 23:51:27 +0300 Subject: [PATCH 1/5] Editor Fix --- Editor/DefinitionCreatorEditor.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Editor/DefinitionCreatorEditor.cs b/Editor/DefinitionCreatorEditor.cs index f1257a5..2472678 100644 --- a/Editor/DefinitionCreatorEditor.cs +++ b/Editor/DefinitionCreatorEditor.cs @@ -142,8 +142,9 @@ namespace Syntriax.Modules.Movement.Editor string jsonText = JsonUtility.ToJson(definition, true); string path = $"Assets/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{definition.Name}.json"; - if (!EditorUtility.DisplayDialog("Conflict", $"\"{path}\" already exists, do you want to overwrite?", "Overwrite", "Cancel")) - return; + if (System.IO.File.Exists($"{Application.dataPath}/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{definition.Name}.json")) + if (!EditorUtility.DisplayDialog("Conflict", $"\"{path}\" already exists, do you want to overwrite?", "Overwrite", "Cancel")) + return; System.IO.File.WriteAllText(path, jsonText); AssetDatabase.Refresh(); From d11aab596d77e58cd23020ad9a656fe5d9314490 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 19 Jan 2023 20:13:12 +0300 Subject: [PATCH 2/5] Fixed Movement Controller not updating the new movement with the old information --- Runtime/MovementController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Runtime/MovementController.cs b/Runtime/MovementController.cs index 729247e..e16f990 100644 --- a/Runtime/MovementController.cs +++ b/Runtime/MovementController.cs @@ -49,6 +49,7 @@ namespace Syntriax.Modules.Movement toggleStateOnGameObject.OnToggleStateChanged += (_) => InvokeOnMoveAction(); ToggleStateMember.OnToggleStateChanged += (_) => InvokeOnMoveAction(); + OnMovementActivated += (newMovement) => newMovement.Move(lastMove); } protected virtual void FixedUpdate() From 25be6929f2d4323c37e9d78b6cfaa444f701169b Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 20 Mar 2023 22:39:21 +0300 Subject: [PATCH 3/5] BREAKING CHANGE: Toggle 0.2.0 --- Editor/DefinitionCreatorEditor.cs | 2 +- README.md | 6 +++--- Runtime/Bases/MovementBase.cs | 8 +++----- Runtime/IMovementController.cs | 6 +++--- Runtime/MovementController.cs | 18 +++++++++--------- package.json | 4 ++-- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Editor/DefinitionCreatorEditor.cs b/Editor/DefinitionCreatorEditor.cs index 2472678..4e49da0 100644 --- a/Editor/DefinitionCreatorEditor.cs +++ b/Editor/DefinitionCreatorEditor.cs @@ -99,7 +99,7 @@ namespace Syntriax.Modules.Movement.Editor movementDefinition.MonoBehaviours = new string[] { typeof(MovementController).FullName, - typeof(ToggleState.ToggleStateMonoBehaviour).FullName + typeof(State.StateEnableMonoBehaviour).FullName }; UpdateSerializedObject(); diff --git a/README.md b/README.md index a493a49..f524668 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Movement (Work In Progress) ## Dependencies -1. [ToggleState Module](https://git.syntriax.com/Syntriax/ToggleState) +1. [State Module](https://git.syntriax.com/Syntriax/State) 2. [Trigger Module](https://git.syntriax.com/Syntriax/Trigger) 3. [Factory Module](https://git.syntriax.com/Syntriax/Factory) @@ -32,7 +32,7 @@ Make sure to separately clone these modules along with this one too. #### Longer 1. Clone the module to a folder in your Assets folder -2. Add `ToggleStateMonoBehaviour` component to your Player `GameObject` +2. Add `StateEnableMonoBehaviour` component to your Player `GameObject` 3. Add `MovementController` component to your Player `GameObject` 4. Add `AirMovement1D` component to your Player `GameObject` 5. Add `GroundMovement1D` component to your Player `GameObject` (make sure it's bellow `AirMovement1D`) @@ -42,7 +42,7 @@ Make sure to separately clone these modules along with this one too. --- -This should give you a movement where you can disable the controller through the `IToggleState`, and you should be able to see a the movement changes when the character is not touching the ground. +This should give you a movement where you can disable the controller through the `IStateEnable`, and you should be able to see a the movement changes when the character is not touching the ground. You can add your own movement implementations with bases under the `Bases` folder, or straight up from the `IMovement` interface. diff --git a/Runtime/Bases/MovementBase.cs b/Runtime/Bases/MovementBase.cs index 6b88214..3419f9a 100644 --- a/Runtime/Bases/MovementBase.cs +++ b/Runtime/Bases/MovementBase.cs @@ -1,12 +1,12 @@ using System; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; using UnityEngine; namespace Syntriax.Modules.Movement { public abstract class MovementBase : MonoBehaviour, IMovement { - protected IToggleState toggleState = null; + protected IStateEnable stateEnable = null; protected IMovementController movementController = null; public float BaseSpeed { get; set; } = 1f; @@ -27,8 +27,6 @@ namespace Syntriax.Modules.Movement } } - public IToggleState ToggleState { get; protected set; } = null; - /// public abstract void ApplyMovement(); @@ -46,7 +44,7 @@ namespace Syntriax.Modules.Movement protected virtual void Start() { - toggleState = GetComponent(); + stateEnable = GetComponent(); movementController = GetComponent(); movementController.OnMovementActivated += OnActivated; diff --git a/Runtime/IMovementController.cs b/Runtime/IMovementController.cs index d72295b..a4d05f4 100644 --- a/Runtime/IMovementController.cs +++ b/Runtime/IMovementController.cs @@ -1,15 +1,15 @@ using System; using System.Collections.Generic; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; namespace Syntriax.Modules.Movement { public interface IMovementController { /// - /// Member to switch on or off + /// Member to switch on or off /// - IToggleState ToggleStateMember { get; } + IStateEnable StateEnableMember { get; } /// /// Currently active diff --git a/Runtime/MovementController.cs b/Runtime/MovementController.cs index e16f990..3c44f3a 100644 --- a/Runtime/MovementController.cs +++ b/Runtime/MovementController.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using Syntriax.Modules.ToggleState; +using Syntriax.Modules.State; using UnityEngine; namespace Syntriax.Modules.Movement @@ -31,13 +31,13 @@ namespace Syntriax.Modules.Movement } } - private bool areBothToggleStatesToggled => ToggleStateMember.IsToggledNullChecked() && toggleStateOnGameObject.IsToggledNullChecked(); + private bool areBothStateEnablesToggled => StateEnableMember.IsEnabledNullChecked() && stateEnableOnGameObject.IsEnabledNullChecked(); public List Movements { get; protected set; } = new List(32); - public IToggleState ToggleStateMember { get; protected set; } = new ToggleStateMember(true); + public IStateEnable StateEnableMember { get; protected set; } = new StateEnableMember(true); - protected IToggleState toggleStateOnGameObject = null; + protected IStateEnable stateEnableOnGameObject = null; protected virtual void Start() { @@ -45,16 +45,16 @@ namespace Syntriax.Modules.Movement gameObject.AddComponent(); RecacheMovements(); - toggleStateOnGameObject = GetComponent(); + stateEnableOnGameObject = GetComponent(); - toggleStateOnGameObject.OnToggleStateChanged += (_) => InvokeOnMoveAction(); - ToggleStateMember.OnToggleStateChanged += (_) => InvokeOnMoveAction(); + stateEnableOnGameObject.OnEnabledChanged += (_) => InvokeOnMoveAction(); + StateEnableMember.OnEnabledChanged += (_) => InvokeOnMoveAction(); OnMovementActivated += (newMovement) => newMovement.Move(lastMove); } protected virtual void FixedUpdate() { - if (!areBothToggleStatesToggled) + if (!areBothStateEnablesToggled) return; ActiveMovement?.ApplyMovement(); @@ -96,7 +96,7 @@ namespace Syntriax.Modules.Movement private void InvokeOnMoveAction() { - if (!areBothToggleStatesToggled) + if (!areBothStateEnablesToggled) return; OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z); diff --git a/package.json b/package.json index 887d512..8d1bca0 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.syntriax.movement", - "version": "0.1.4", + "version": "0.2.0", "displayName": "Movement Module", - "description": "Dependends On:\nhttps://git.syntriax.com/Syntriax/ToggleState.git\nhttps://git.syntriax.com/Syntriax/Trigger.git\nhttps://git.syntriax.com/Syntriax/Factory.git", + "description": "Dependends On:\nhttps://git.syntriax.com/Syntriax/State.git\nhttps://git.syntriax.com/Syntriax/Trigger.git\nhttps://git.syntriax.com/Syntriax/Factory.git", "unity": "2019.1", "documentationUrl": "https://git.syntriax.com/Syntriax/Movement.git", "keywords": ["Movement"], From 0fc73f330b3288902daf2edb48715215eba12bca Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 20 Mar 2023 22:51:19 +0300 Subject: [PATCH 4/5] refactor: Replaced "Member" IStateEnable --- Runtime/IMovementController.cs | 4 ++-- Runtime/MovementController.cs | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Runtime/IMovementController.cs b/Runtime/IMovementController.cs index a4d05f4..c01a1d6 100644 --- a/Runtime/IMovementController.cs +++ b/Runtime/IMovementController.cs @@ -7,9 +7,9 @@ namespace Syntriax.Modules.Movement public interface IMovementController { /// - /// Member to switch on or off + /// to control the state of the is on or off /// - IStateEnable StateEnableMember { get; } + IStateEnable StateEnable { get; } /// /// Currently active diff --git a/Runtime/MovementController.cs b/Runtime/MovementController.cs index 3c44f3a..cc9dfe2 100644 --- a/Runtime/MovementController.cs +++ b/Runtime/MovementController.cs @@ -31,13 +31,17 @@ namespace Syntriax.Modules.Movement } } - private bool areBothStateEnablesToggled => StateEnableMember.IsEnabledNullChecked() && stateEnableOnGameObject.IsEnabledNullChecked(); - public List Movements { get; protected set; } = new List(32); - public IStateEnable StateEnableMember { get; protected set; } = new StateEnableMember(true); - - protected IStateEnable stateEnableOnGameObject = null; + private IStateEnable _stateEnable = null; + public IStateEnable StateEnable + { + get + { + _stateEnable = _stateEnable ?? GetComponent() ?? gameObject.AddComponent(); + return _stateEnable; + } + } protected virtual void Start() { @@ -45,16 +49,14 @@ namespace Syntriax.Modules.Movement gameObject.AddComponent(); RecacheMovements(); - stateEnableOnGameObject = GetComponent(); - stateEnableOnGameObject.OnEnabledChanged += (_) => InvokeOnMoveAction(); - StateEnableMember.OnEnabledChanged += (_) => InvokeOnMoveAction(); + StateEnable.OnEnabledChanged += (_) => InvokeOnMoveAction(); OnMovementActivated += (newMovement) => newMovement.Move(lastMove); } protected virtual void FixedUpdate() { - if (!areBothStateEnablesToggled) + if (!StateEnable.IsEnabledNullChecked()) return; ActiveMovement?.ApplyMovement(); @@ -86,6 +88,7 @@ namespace Syntriax.Modules.Movement } private Vector3 lastMove = Vector3.zero; + public void Move(float x = 0, float y = 0, float z = 0) { ActiveMovement?.Move(x, y, z); @@ -96,7 +99,7 @@ namespace Syntriax.Modules.Movement private void InvokeOnMoveAction() { - if (!areBothStateEnablesToggled) + if (!StateEnable.IsEnabledNullChecked()) return; OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z); From a4bb04860c8754bee32331c767962c2b130d5ba9 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Mon, 20 Mar 2023 22:51:49 +0300 Subject: [PATCH 5/5] feat: Sample Movements Are Now Looking Up Parents For Rigidbodies --- Samples/AirMovement1D.cs | 2 +- Samples/GroundMovement1D.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Samples/AirMovement1D.cs b/Samples/AirMovement1D.cs index b7345b1..f1bf410 100644 --- a/Samples/AirMovement1D.cs +++ b/Samples/AirMovement1D.cs @@ -14,7 +14,7 @@ namespace Syntriax.Modules.Movement.Samples { base.Start(); - rigid = GetComponent(); + rigid = GetComponentInParent(); groundTrigger = GetComponentInChildren(); if (groundTrigger != null) diff --git a/Samples/GroundMovement1D.cs b/Samples/GroundMovement1D.cs index 6f29b2b..cbb4d38 100644 --- a/Samples/GroundMovement1D.cs +++ b/Samples/GroundMovement1D.cs @@ -16,7 +16,7 @@ namespace Syntriax.Modules.Movement.Samples { base.Start(); - rigid = GetComponent(); + rigid = GetComponentInParent(); groundTrigger = GetComponentInChildren(); if (groundTrigger != null)