InputCollection Field added to IVariableMovementWithState + Bug Fix
This commit is contained in:
parent
e35cdcb069
commit
9e3efe49a0
|
@ -22,6 +22,8 @@ namespace Syntriax.Modules.Movement
|
|||
IMovement oldMovement = _activeMovement;
|
||||
|
||||
_activeMovement = value;
|
||||
|
||||
if (oldMovement != null)
|
||||
OnMovementDeactivated.Invoke(oldMovement);
|
||||
OnMovementActivated.Invoke(value);
|
||||
}
|
||||
|
@ -29,7 +31,6 @@ namespace Syntriax.Modules.Movement
|
|||
|
||||
public List<IMovement> Movements { get; protected set; } = null;
|
||||
|
||||
|
||||
protected IToggleState toggleState = null;
|
||||
|
||||
protected virtual void Awake()
|
||||
|
@ -64,7 +65,6 @@ namespace Syntriax.Modules.Movement
|
|||
|
||||
foreach (IMovement movement in Movements)
|
||||
movement.OnTakeOverStateChanged.AddListener(OnTakeOverListener);
|
||||
|
||||
}
|
||||
|
||||
private void OnTakeOverListener(bool arg0) => UpdateActiveMovement();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using UnityEngine.Events;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace Syntriax.Modules.Movement.VariableMovement
|
||||
{
|
||||
|
@ -6,5 +7,6 @@ namespace Syntriax.Modules.Movement.VariableMovement
|
|||
{
|
||||
bool Enabled { get; set; }
|
||||
UnityEvent<bool> OnToggleStateChanged { get; }
|
||||
IInputActionCollection InputCollection { set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,18 @@ namespace Syntriax.Modules.Movement.VariableMovement
|
|||
public class VariableMovementController : MonoBehaviour, IVariableMovementController
|
||||
{
|
||||
public UnityEvent<IVariableMovement> OnVariableMovementChanged { get; protected set; } = null;
|
||||
public IInputActionCollection InputActionCollection { 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
|
||||
{
|
||||
|
@ -63,9 +74,6 @@ namespace Syntriax.Modules.Movement.VariableMovement
|
|||
|
||||
public void LoadVariableMovementCollection(VMCollection collection)
|
||||
{
|
||||
if (InputActionCollection == null)
|
||||
throw new System.NullReferenceException("InputActionCollection must be set on the VariableMovementController to load a collection!");
|
||||
|
||||
this.collection = collection;
|
||||
isSet = true;
|
||||
|
||||
|
|
|
@ -26,20 +26,7 @@ namespace Syntriax.Modules.Movement.VariableMovement
|
|||
get => _asset;
|
||||
set
|
||||
{
|
||||
if (actionReference != null)
|
||||
{
|
||||
actionReference.performed -= Performed;
|
||||
actionReference.canceled -= Cancelled;
|
||||
}
|
||||
|
||||
foreach (InputAction action in inputClass)
|
||||
if (action.name == value.Name)
|
||||
{
|
||||
actionReference = action;
|
||||
actionReference.performed += Performed;
|
||||
actionReference.canceled += Cancelled;
|
||||
break;
|
||||
}
|
||||
UpdateBindings();
|
||||
|
||||
_asset = value;
|
||||
|
||||
|
@ -47,17 +34,48 @@ namespace Syntriax.Modules.Movement.VariableMovement
|
|||
}
|
||||
}
|
||||
|
||||
protected readonly IInputActionCollection inputClass;
|
||||
private IInputActionCollection _inputCollection = null;
|
||||
public IInputActionCollection InputCollection
|
||||
{
|
||||
set
|
||||
{
|
||||
if (_inputCollection == value)
|
||||
return;
|
||||
|
||||
_inputCollection = value;
|
||||
UpdateBindings();
|
||||
}
|
||||
}
|
||||
|
||||
protected InputAction actionReference = null;
|
||||
|
||||
public VariableMovementWithState(VMAsset asset, IInputActionCollection inputClass)
|
||||
public VariableMovementWithState(VMAsset asset, IInputActionCollection inputCollection)
|
||||
{
|
||||
this.inputClass = inputClass;
|
||||
InputCollection = inputCollection;
|
||||
OnToggleStateChanged = new UnityEvent<bool>();
|
||||
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.Name)
|
||||
{
|
||||
actionReference = action;
|
||||
actionReference.performed += Performed;
|
||||
actionReference.canceled += Cancelled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue