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