0.2.0
This commit is contained in:
commit
0a6f26461e
|
@ -99,7 +99,7 @@ namespace Syntriax.Modules.Movement.Editor
|
||||||
movementDefinition.MonoBehaviours = new string[]
|
movementDefinition.MonoBehaviours = new string[]
|
||||||
{
|
{
|
||||||
typeof(MovementController).FullName,
|
typeof(MovementController).FullName,
|
||||||
typeof(ToggleState.ToggleStateMonoBehaviour).FullName
|
typeof(State.StateEnableMonoBehaviour).FullName
|
||||||
};
|
};
|
||||||
|
|
||||||
UpdateSerializedObject();
|
UpdateSerializedObject();
|
||||||
|
@ -142,6 +142,7 @@ namespace Syntriax.Modules.Movement.Editor
|
||||||
string jsonText = JsonUtility.ToJson(definition, true);
|
string jsonText = JsonUtility.ToJson(definition, true);
|
||||||
string path = $"Assets/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{definition.Name}.json";
|
string path = $"Assets/Resources/{MovementDefinitionFactory.ResourceDirectoryToDefinitions}{definition.Name}.json";
|
||||||
|
|
||||||
|
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"))
|
if (!EditorUtility.DisplayDialog("Conflict", $"\"{path}\" already exists, do you want to overwrite?", "Overwrite", "Cancel"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Movement (Work In Progress)
|
# Movement (Work In Progress)
|
||||||
|
|
||||||
## Dependencies
|
## 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)
|
2. [Trigger Module](https://git.syntriax.com/Syntriax/Trigger)
|
||||||
3. [Factory Module](https://git.syntriax.com/Syntriax/Factory)
|
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
|
#### Longer
|
||||||
|
|
||||||
1. Clone the module to a folder in your Assets folder
|
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`
|
3. Add `MovementController` component to your Player `GameObject`
|
||||||
4. Add `AirMovement1D` 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`)
|
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.
|
You can add your own movement implementations with bases under the `Bases` folder, or straight up from the `IMovement` interface.
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement
|
||||||
{
|
{
|
||||||
public abstract class MovementBase : MonoBehaviour, IMovement
|
public abstract class MovementBase : MonoBehaviour, IMovement
|
||||||
{
|
{
|
||||||
protected IToggleState toggleState = null;
|
protected IStateEnable stateEnable = null;
|
||||||
protected IMovementController movementController = null;
|
protected IMovementController movementController = null;
|
||||||
|
|
||||||
public float BaseSpeed { get; set; } = 1f;
|
public float BaseSpeed { get; set; } = 1f;
|
||||||
|
@ -27,8 +27,6 @@ namespace Syntriax.Modules.Movement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IToggleState ToggleState { get; protected set; } = null;
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public abstract void ApplyMovement();
|
public abstract void ApplyMovement();
|
||||||
|
|
||||||
|
@ -46,7 +44,7 @@ namespace Syntriax.Modules.Movement
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
toggleState = GetComponent<IToggleState>();
|
stateEnable = GetComponent<IStateEnable>();
|
||||||
movementController = GetComponent<IMovementController>();
|
movementController = GetComponent<IMovementController>();
|
||||||
|
|
||||||
movementController.OnMovementActivated += OnActivated;
|
movementController.OnMovementActivated += OnActivated;
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement
|
||||||
{
|
{
|
||||||
public interface IMovementController
|
public interface IMovementController
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Member <see cref="IToggleState"/> to switch on or off
|
/// <see cref="IStateEnable"/> to control the state of the <see cref="IMovementController"/> is on or off
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IToggleState ToggleStateMember { get; }
|
IStateEnable StateEnable { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Currently active <see cref="IMovement"/>
|
/// Currently active <see cref="IMovement"/>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Syntriax.Modules.ToggleState;
|
using Syntriax.Modules.State;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Syntriax.Modules.Movement
|
namespace Syntriax.Modules.Movement
|
||||||
|
@ -31,13 +31,17 @@ namespace Syntriax.Modules.Movement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool areBothToggleStatesToggled => ToggleStateMember.IsToggledNullChecked() && toggleStateOnGameObject.IsToggledNullChecked();
|
|
||||||
|
|
||||||
public List<IMovement> Movements { get; protected set; } = new List<IMovement>(32);
|
public List<IMovement> Movements { get; protected set; } = new List<IMovement>(32);
|
||||||
|
|
||||||
public IToggleState ToggleStateMember { get; protected set; } = new ToggleStateMember(true);
|
private IStateEnable _stateEnable = null;
|
||||||
|
public IStateEnable StateEnable
|
||||||
protected IToggleState toggleStateOnGameObject = null;
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
_stateEnable = _stateEnable ?? GetComponent<State.IStateEnable>() ?? gameObject.AddComponent<State.StateEnableMonoBehaviour>();
|
||||||
|
return _stateEnable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
|
@ -45,15 +49,14 @@ namespace Syntriax.Modules.Movement
|
||||||
gameObject.AddComponent<DefaultMovement>();
|
gameObject.AddComponent<DefaultMovement>();
|
||||||
|
|
||||||
RecacheMovements();
|
RecacheMovements();
|
||||||
toggleStateOnGameObject = GetComponent<IToggleState>();
|
|
||||||
|
|
||||||
toggleStateOnGameObject.OnToggleStateChanged += (_) => InvokeOnMoveAction();
|
StateEnable.OnEnabledChanged += (_) => InvokeOnMoveAction();
|
||||||
ToggleStateMember.OnToggleStateChanged += (_) => InvokeOnMoveAction();
|
OnMovementActivated += (newMovement) => newMovement.Move(lastMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void FixedUpdate()
|
protected virtual void FixedUpdate()
|
||||||
{
|
{
|
||||||
if (!areBothToggleStatesToggled)
|
if (!StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ActiveMovement?.ApplyMovement();
|
ActiveMovement?.ApplyMovement();
|
||||||
|
@ -85,6 +88,7 @@ namespace Syntriax.Modules.Movement
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector3 lastMove = Vector3.zero;
|
private Vector3 lastMove = Vector3.zero;
|
||||||
|
|
||||||
public void Move(float x = 0, float y = 0, float z = 0)
|
public void Move(float x = 0, float y = 0, float z = 0)
|
||||||
{
|
{
|
||||||
ActiveMovement?.Move(x, y, z);
|
ActiveMovement?.Move(x, y, z);
|
||||||
|
@ -95,7 +99,7 @@ namespace Syntriax.Modules.Movement
|
||||||
|
|
||||||
private void InvokeOnMoveAction()
|
private void InvokeOnMoveAction()
|
||||||
{
|
{
|
||||||
if (!areBothToggleStatesToggled)
|
if (!StateEnable.IsEnabledNullChecked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z);
|
OnMoveCalled?.Invoke(lastMove.x, lastMove.y, lastMove.z);
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Syntriax.Modules.Movement.Samples
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
|
|
||||||
rigid = GetComponent<Rigidbody2D>();
|
rigid = GetComponentInParent<Rigidbody2D>();
|
||||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||||
|
|
||||||
if (groundTrigger != null)
|
if (groundTrigger != null)
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Syntriax.Modules.Movement.Samples
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
|
|
||||||
rigid = GetComponent<Rigidbody2D>();
|
rigid = GetComponentInParent<Rigidbody2D>();
|
||||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||||
|
|
||||||
if (groundTrigger != null)
|
if (groundTrigger != null)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
{
|
{
|
||||||
"name": "com.syntriax.movement",
|
"name": "com.syntriax.movement",
|
||||||
"version": "0.1.4",
|
"version": "0.2.0",
|
||||||
"displayName": "Movement Module",
|
"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",
|
"unity": "2019.1",
|
||||||
"documentationUrl": "https://git.syntriax.com/Syntriax/Movement.git",
|
"documentationUrl": "https://git.syntriax.com/Syntriax/Movement.git",
|
||||||
"keywords": ["Movement"],
|
"keywords": ["Movement"],
|
||||||
|
|
Loading…
Reference in New Issue