Switched from UnityEvent to System.Action

This commit is contained in:
2022-11-13 18:07:54 +03:00
parent 8a1fdc6f9e
commit d76675b6f1
22 changed files with 44 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
using UnityEngine.Events;
using System;
using UnityEngine.InputSystem;
namespace Syntriax.Modules.Movement.VariableMovement
@@ -6,7 +6,7 @@ namespace Syntriax.Modules.Movement.VariableMovement
public interface IVariableMovementController
{
IVariableMovement ActiveVariableMovement { get; }
UnityEvent<IVariableMovement> OnVariableMovementChanged { get; }
Action<IVariableMovement> OnVariableMovementChanged { get; set; }
IInputActionCollection InputActionCollection { get; set; }
void LoadVariableMovementCollection(VMCollection collection);

View File

@@ -1,4 +1,4 @@
using UnityEngine.Events;
using System;
using UnityEngine.InputSystem;
namespace Syntriax.Modules.Movement.VariableMovement
@@ -6,7 +6,7 @@ namespace Syntriax.Modules.Movement.VariableMovement
public interface IVariableMovementWithState : IVariableMovement
{
bool Enabled { get; set; }
UnityEvent<bool> OnToggleStateChanged { get; }
Action<bool> OnToggleStateChanged { get; set; }
IInputActionCollection InputCollection { set; }
}
}

View File

@@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
namespace Syntriax.Modules.Movement.VariableMovement
{
public class VariableMovementController : MonoBehaviour, IVariableMovementController
{
public UnityEvent<IVariableMovement> OnVariableMovementChanged { get; protected set; } = null;
public Action<IVariableMovement> OnVariableMovementChanged { get; set; } = null;
private IInputActionCollection _inputActionCollection = null;
public IInputActionCollection InputActionCollection
{
@@ -43,7 +42,6 @@ namespace Syntriax.Modules.Movement.VariableMovement
protected virtual void Awake()
{
OnVariableMovementChanged = new UnityEvent<IVariableMovement>();
defaultVariableMovement = new VariableMovement();
variableMovementsWithState = new List<IVariableMovementWithState>(16);
}
@@ -51,8 +49,8 @@ namespace Syntriax.Modules.Movement.VariableMovement
protected virtual void Start()
{
movementController = GetComponent<IMovementController>();
movementController.OnMovementActivated.AddListener(SetMultiplierToActiveMovement);
movementController.OnMovementDeactivated.AddListener(ResetMultiplierToDefault);
movementController.OnMovementActivated += SetMultiplierToActiveMovement;
movementController.OnMovementDeactivated += ResetMultiplierToDefault;
}
private void ResetMultiplierToDefault(IMovement currentMovement)
@@ -91,13 +89,13 @@ namespace Syntriax.Modules.Movement.VariableMovement
protected virtual void SubscribeToMovements()
{
foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState)
variableMovementWithState.OnToggleStateChanged.AddListener(VariableMovementStateListener);
variableMovementWithState.OnToggleStateChanged += VariableMovementStateListener;
}
protected virtual void UnsubscribeFromMovements()
{
foreach (IVariableMovementWithState variableMovementWithState in variableMovementsWithState)
variableMovementWithState.OnToggleStateChanged.RemoveListener(VariableMovementStateListener);
variableMovementWithState.OnToggleStateChanged -= VariableMovementStateListener;
}
private void VariableMovementStateListener(bool arg0) => UpdateActiveVariableMovement();

View File

@@ -1,11 +1,11 @@
using UnityEngine.Events;
using System;
using UnityEngine.InputSystem;
namespace Syntriax.Modules.Movement.VariableMovement
{
public class VariableMovementWithState : IVariableMovementWithState
{
public UnityEvent<bool> OnToggleStateChanged { get; protected set; } = null;
public Action<bool> OnToggleStateChanged { get; set; } = null;
private bool _enabled = false;
public bool Enabled
{
@@ -52,7 +52,6 @@ namespace Syntriax.Modules.Movement.VariableMovement
public VariableMovementWithState(VMAsset asset, IInputActionCollection inputCollection)
{
InputCollection = inputCollection;
OnToggleStateChanged = new UnityEvent<bool>();
Asset = asset;
}