Switched from UnityEvent to System.Action
This commit is contained in:
parent
8a1fdc6f9e
commit
d76675b6f1
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c348589c341f3d4f8db2e34198ec32e
|
||||
guid: 8747cc51a59e7a14fae4687c7136d15b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91b4c4b7439cfcb448a15d0f2ce12ff9
|
||||
guid: 8dc876763de82b74cb9a05685d57e841
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1213a467d17883844b2dc54d266cf211
|
||||
guid: df412a9878b7d5b43ab34aef7261ec3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a31fdb05e206b44cbe615353e924344
|
||||
guid: d1b41d4e3ee5ce24eaef42d5c8fc8c3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement.ColliderTrigger
|
||||
{
|
||||
|
@ -7,6 +7,6 @@ namespace Syntriax.Modules.Movement.ColliderTrigger
|
|||
{
|
||||
LayerMask ColliderMask { get; set; }
|
||||
bool IsTrigerred { get; }
|
||||
UnityEvent<bool> OnTriggered { get; }
|
||||
Action<bool> OnTriggered { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ab2264f0e385af4d8decc8750297a9e
|
||||
guid: e199ccade2250b646abfd859e4aa1e7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement.ColliderTrigger
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace Syntriax.Modules.Movement.ColliderTrigger
|
|||
|
||||
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
|
||||
|
||||
public UnityEvent<bool> OnTriggered { get; protected set; } = null;
|
||||
public Action<bool> OnTriggered { get; set; } = null;
|
||||
public bool IsTrigerred
|
||||
{
|
||||
get => _isTrigerred;
|
||||
|
@ -26,9 +26,6 @@ namespace Syntriax.Modules.Movement.ColliderTrigger
|
|||
}
|
||||
}
|
||||
|
||||
protected void Awake()
|
||||
=> OnTriggered = new UnityEvent<bool>();
|
||||
|
||||
protected void FixedUpdate()
|
||||
=> IsTrigerred = Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, results, ColliderMask) > 0;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 090650329160e7b42ba89ccfad00375e
|
||||
guid: cbd3633509c80ca49b6ae013c990bdbe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using UnityEngine.Events;
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
|
@ -9,7 +9,7 @@ namespace Syntriax.Modules.Movement
|
|||
|
||||
bool CanTakeOver { get; }
|
||||
|
||||
UnityEvent<bool> OnTakeOverStateChanged { get; }
|
||||
Action<bool> OnTakeOverStateChanged { get; set; }
|
||||
|
||||
void Move(float x = 0f, float y = 0f, float z = 0f);
|
||||
void ApplyMovement();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
|
@ -8,8 +8,8 @@ namespace Syntriax.Modules.Movement
|
|||
IMovement ActiveMovement { get; }
|
||||
List<IMovement> Movements { get; }
|
||||
|
||||
UnityEvent<IMovement> OnMovementDeactivated { get; }
|
||||
UnityEvent<IMovement> OnMovementActivated { get; }
|
||||
Action<IMovement> OnMovementDeactivated { get; set; }
|
||||
Action<IMovement> OnMovementActivated { get; set; }
|
||||
|
||||
void RecacheMovements();
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
|||
{
|
||||
base.Start();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
groundTrigger.OnTriggered.AddListener(OnGroundTrigger);
|
||||
groundTrigger.OnTriggered += OnGroundTrigger;
|
||||
}
|
||||
|
||||
private void OnGroundTrigger(bool isGrounded)
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
|||
{
|
||||
base.Start();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
groundTrigger.OnTriggered.AddListener(OnGroundTrigger);
|
||||
groundTrigger.OnTriggered += OnGroundTrigger;
|
||||
}
|
||||
|
||||
private void OnGroundTrigger(bool isGrounded)
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
|||
{
|
||||
base.Start();
|
||||
groundTrigger = GetComponentInChildren<IGroundTrigger>();
|
||||
groundTrigger.OnTriggered.AddListener(OnGroundTrigger);
|
||||
groundTrigger.OnTriggered += OnGroundTrigger;
|
||||
}
|
||||
|
||||
private void OnGroundTrigger(bool isGrounded)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Syntriax.Modules.Movement.State;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
|||
public float BaseSpeed { get; set; } = 1f;
|
||||
public float MovementMultiplier { get; set; } = 1f;
|
||||
|
||||
public UnityEvent<bool> OnTakeOverStateChanged { get; protected set; } = null;
|
||||
public Action<bool> OnTakeOverStateChanged { get; set; } = null;
|
||||
public bool CanTakeOver
|
||||
{
|
||||
get => _canTakeOver;
|
||||
|
@ -32,19 +32,14 @@ namespace Syntriax.Modules.Movement.Implementations.TwoDimensional
|
|||
|
||||
public IToggleState ToggleState { get; protected set; } = null;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
OnTakeOverStateChanged = new UnityEvent<bool>();
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
rigid = GetComponent<Rigidbody2D>();
|
||||
toggleState = GetComponent<ToggleState>();
|
||||
movementController = GetComponent<IMovementController>();
|
||||
|
||||
movementController.OnMovementActivated.AddListener(OnActivated);
|
||||
movementController.OnMovementDeactivated.AddListener(OnDeactivated);
|
||||
movementController.OnMovementActivated += OnActivated;
|
||||
movementController.OnMovementDeactivated += OnDeactivated;
|
||||
}
|
||||
|
||||
protected abstract void OnDeactivated();
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Syntriax.Modules.Movement.State;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement
|
||||
{
|
||||
public class MovementController : MonoBehaviour, IMovementController
|
||||
{
|
||||
public UnityEvent<IMovement> OnMovementDeactivated { get; protected set; } = null;
|
||||
public UnityEvent<IMovement> OnMovementActivated { get; protected set; } = null;
|
||||
public Action<IMovement> OnMovementDeactivated { get; set; } = null;
|
||||
public Action<IMovement> OnMovementActivated { get; set; } = null;
|
||||
|
||||
private IMovement _activeMovement = null;
|
||||
public IMovement ActiveMovement
|
||||
|
@ -35,8 +35,6 @@ namespace Syntriax.Modules.Movement
|
|||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
OnMovementDeactivated = new UnityEvent<IMovement>();
|
||||
OnMovementActivated = new UnityEvent<IMovement>();
|
||||
Movements = new List<IMovement>(32);
|
||||
}
|
||||
|
||||
|
@ -57,14 +55,14 @@ namespace Syntriax.Modules.Movement
|
|||
public virtual void RecacheMovements()
|
||||
{
|
||||
foreach (IMovement movement in Movements)
|
||||
movement.OnTakeOverStateChanged.RemoveListener(OnTakeOverListener);
|
||||
movement.OnTakeOverStateChanged -= OnTakeOverListener;
|
||||
|
||||
Movements.Clear();
|
||||
GetComponents<IMovement>(Movements);
|
||||
UpdateActiveMovement();
|
||||
|
||||
foreach (IMovement movement in Movements)
|
||||
movement.OnTakeOverStateChanged.AddListener(OnTakeOverListener);
|
||||
movement.OnTakeOverStateChanged += OnTakeOverListener;
|
||||
}
|
||||
|
||||
private void OnTakeOverListener(bool arg0) => UpdateActiveMovement();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
using UnityEngine.Events;
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Modules.Movement.State
|
||||
{
|
||||
public interface IToggleState
|
||||
{
|
||||
bool Toggled { get; set; }
|
||||
UnityEvent<bool> OnToggleStateChanged { get; }
|
||||
Action<bool> OnToggleStateChanged { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using UnityEngine.Events;
|
||||
using System;
|
||||
|
||||
namespace Syntriax.Modules.Movement.State
|
||||
{
|
||||
|
@ -20,6 +20,6 @@ namespace Syntriax.Modules.Movement.State
|
|||
}
|
||||
}
|
||||
|
||||
public UnityEvent<bool> OnToggleStateChanged { get; protected set; } = new UnityEvent<bool>();
|
||||
public Action<bool> OnToggleStateChanged { get; set; } = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Syntriax.Modules.Movement.State
|
||||
{
|
||||
|
@ -20,6 +20,6 @@ namespace Syntriax.Modules.Movement.State
|
|||
}
|
||||
}
|
||||
|
||||
public UnityEvent<bool> OnToggleStateChanged { get; protected set; } = new UnityEvent<bool>();
|
||||
public Action<bool> OnToggleStateChanged { get; set; } = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue