Compare commits

..

No commits in common. "d3db00722ac435debba1fc04ce404fed493919b7" and "01c76e36ad7e61e2985e68e59c1b7fa2bb9c79d4" have entirely different histories.

7 changed files with 17 additions and 60 deletions

View File

@ -2,7 +2,7 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class Box2DColliderTriggerArea : ColliderTriggerAreaBase<Collider2D>
public class Box2DColliderTriggerArea : ColliderTriggerAreaBase
{
protected override int TriggerCount
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocResults, ColliderMask);
@ -10,10 +10,7 @@ namespace Syntriax.Modules.Trigger
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
}
#endif

View File

@ -2,7 +2,7 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class Box2DColliderTriggerAreaWithRotation : ColliderTriggerAreaBase<Collider2D>
public class Box2DColliderTriggerAreaWithRotation : ColliderTriggerAreaBase
{
protected override int TriggerCount
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, transform.rotation.eulerAngles.z, nonAllocResults, ColliderMask);
@ -10,10 +10,7 @@ namespace Syntriax.Modules.Trigger
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
}

View File

@ -1,22 +0,0 @@
using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public class BoxColliderTriggerArea : ColliderTriggerAreaBase<Collider>
{
protected override int TriggerCount
=> Physics.OverlapBoxNonAlloc(transform.position, transform.localScale * .5f, nonAllocResults, transform.rotation, ColliderMask);
#if UNITY_EDITOR
private void OnDrawGizmosSelected()
{
if (UnityEditor.EditorApplication.isPlaying)
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
else
Gizmos.color = TriggerCount > 0 ? Color.green : Color.red;
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
}
#endif
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 850a555be97ed9b4a86942b21a6a25e4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,16 +4,16 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger
{
public abstract class ColliderTriggerAreaBase<T> : MonoBehaviour, IColliderTriggerArea where T : Component
public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTriggerArea
{
[SerializeField] private LayerMask colliderMask = ~0;
protected T[] nonAllocResults = new T[32];
protected Collider2D[] nonAllocResults = new Collider2D[32];
protected int previousTriggerCount = 0;
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
public Action<List<Transform>> OnTriggeredTransformsUpdated { get; set; } = null;
public List<Transform> TriggeredTransforms { get; protected set; } = new List<Transform>(32);
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
public List<Collider2D> ColliderList { get; protected set; } = new List<Collider2D>(32);
protected abstract int TriggerCount { get; }
@ -23,11 +23,11 @@ namespace Syntriax.Modules.Trigger
if (!IsArrayAndListIdentical(triggerCount))
{
TriggeredTransforms.Clear();
ColliderList.Clear();
for (int i = 0; i < triggerCount; i++)
TriggeredTransforms.Add(nonAllocResults[i].transform);
ColliderList.Add(nonAllocResults[i]);
OnTriggeredTransformsUpdated?.Invoke(TriggeredTransforms);
OnTriggeredCollidersUpdated?.Invoke(ColliderList);
}
previousTriggerCount = triggerCount;
@ -40,7 +40,7 @@ namespace Syntriax.Modules.Trigger
return false;
for (int i = 0; i < triggerCount; i++)
if (!TriggeredTransforms.Contains(nonAllocResults[i].transform))
if (!ColliderList.Contains(nonAllocResults[i]))
return false;
return true;

View File

@ -1,4 +0,0 @@
namespace Syntriax.Modules.Trigger
{
public class BoxGroundTriggerArea : BoxColliderTriggerArea, IGroundTriggerArea { }
}

View File

@ -12,12 +12,12 @@ namespace Syntriax.Modules.Trigger
LayerMask ColliderMask { get; set; }
/// <summary>
/// Called whenever the list of <see cref="Transform"/> changes
/// Called whenever the list of <see cref="Collider2D"/> changes
/// </summary>
/// <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>
Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; }
/// <value>List of <see cref="Transform"/> that their colliders triggered the <see cref="IColliderTriggerArea"/></value>
List<Transform> TriggeredTransforms { get; }
/// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></value>
List<Collider2D> ColliderList { get; }
}
}