BREAKING CHANGE: IColiderTriggerArea Now Returns Transforms Instead Of Collider2Ds
This commit is contained in:
parent
a4fd3343b1
commit
8b3721eba3
|
@ -2,7 +2,7 @@ using UnityEngine;
|
|||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTriggerArea : ColliderTriggerAreaBase
|
||||
public class Box2DColliderTriggerArea : ColliderTriggerAreaBase<Collider2D>
|
||||
{
|
||||
protected override int TriggerCount
|
||||
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocResults, ColliderMask);
|
||||
|
|
|
@ -2,7 +2,7 @@ using UnityEngine;
|
|||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTriggerAreaWithRotation : ColliderTriggerAreaBase
|
||||
public class Box2DColliderTriggerAreaWithRotation : ColliderTriggerAreaBase<Collider2D>
|
||||
{
|
||||
protected override int TriggerCount
|
||||
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, transform.rotation.eulerAngles.z, nonAllocResults, ColliderMask);
|
||||
|
|
|
@ -4,16 +4,16 @@ using UnityEngine;
|
|||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTriggerArea
|
||||
public abstract class ColliderTriggerAreaBase<T> : MonoBehaviour, IColliderTriggerArea where T : Component
|
||||
{
|
||||
[SerializeField] private LayerMask colliderMask = ~0;
|
||||
|
||||
protected Collider2D[] nonAllocResults = new Collider2D[32];
|
||||
protected T[] nonAllocResults = new T[32];
|
||||
protected int previousTriggerCount = 0;
|
||||
|
||||
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
|
||||
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
|
||||
public List<Collider2D> ColliderList { get; protected set; } = new List<Collider2D>(32);
|
||||
public Action<List<Transform>> OnTriggeredTransformsUpdated { get; set; } = null;
|
||||
public List<Transform> TriggeredTransforms { get; protected set; } = new List<Transform>(32);
|
||||
|
||||
protected abstract int TriggerCount { get; }
|
||||
|
||||
|
@ -23,11 +23,11 @@ namespace Syntriax.Modules.Trigger
|
|||
|
||||
if (!IsArrayAndListIdentical(triggerCount))
|
||||
{
|
||||
ColliderList.Clear();
|
||||
TriggeredTransforms.Clear();
|
||||
for (int i = 0; i < triggerCount; i++)
|
||||
ColliderList.Add(nonAllocResults[i]);
|
||||
TriggeredTransforms.Add(nonAllocResults[i].transform);
|
||||
|
||||
OnTriggeredCollidersUpdated?.Invoke(ColliderList);
|
||||
OnTriggeredTransformsUpdated?.Invoke(TriggeredTransforms);
|
||||
}
|
||||
|
||||
previousTriggerCount = triggerCount;
|
||||
|
@ -40,7 +40,7 @@ namespace Syntriax.Modules.Trigger
|
|||
return false;
|
||||
|
||||
for (int i = 0; i < triggerCount; i++)
|
||||
if (!ColliderList.Contains(nonAllocResults[i]))
|
||||
if (!TriggeredTransforms.Contains(nonAllocResults[i].transform))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
|
@ -12,12 +12,12 @@ namespace Syntriax.Modules.Trigger
|
|||
LayerMask ColliderMask { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the list of <see cref="Collider2D"/> changes
|
||||
/// Called whenever the list of <see cref="Transform"/> changes
|
||||
/// </summary>
|
||||
/// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></value>
|
||||
Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; }
|
||||
/// <value>List of <see cref="Transform"/> that their colliders triggered the <see cref="IColliderTriggerArea"/></value>
|
||||
Action<List<Transform>> OnTriggeredTransformsUpdated { get; set; }
|
||||
|
||||
/// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></value>
|
||||
List<Collider2D> ColliderList { get; }
|
||||
/// <value>List of <see cref="Transform"/> that their colliders triggered the <see cref="IColliderTriggerArea"/></value>
|
||||
List<Transform> TriggeredTransforms { get; }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue