Compare commits

..

No commits in common. "ac1cdfec18463a660dff0b7b89d00db0a581abc2" and "25edbb5e3760422025f02abe0835b68fb6e4fd97" have entirely different histories.

5 changed files with 12 additions and 14 deletions

View File

@ -4,11 +4,11 @@ namespace Syntriax.Modules.Trigger
{ {
public class ColliderTrigger : TriggerBase public class ColliderTrigger : TriggerBase
{ {
protected IColliderTriggerArea colliderTrigger = null; protected IColliderTrigger colliderTrigger = null;
private void Awake() private void Awake()
{ {
colliderTrigger = GetComponent<IColliderTriggerArea>(); colliderTrigger = GetComponent<IColliderTrigger>();
} }
private void FixedUpdate() private void FixedUpdate()

View File

@ -4,14 +4,15 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger namespace Syntriax.Modules.Trigger
{ {
public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTriggerArea public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTrigger
{ {
protected List<Collider2D> results = new List<Collider2D>(32);
protected Collider2D[] nonAllocResults = new Collider2D[32]; protected Collider2D[] nonAllocResults = new Collider2D[32];
protected int previousTriggerCount = 0; protected int previousTriggerCount = 0;
public LayerMask ColliderMask { get; set; } = ~0; public LayerMask ColliderMask { get; set; } = ~0;
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null; public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
public List<Collider2D> ColliderList { get; protected set; } = new List<Collider2D>(32);
protected abstract int TriggerCount { get; } protected abstract int TriggerCount { get; }
@ -21,11 +22,11 @@ namespace Syntriax.Modules.Trigger
if (triggerCount != previousTriggerCount) if (triggerCount != previousTriggerCount)
{ {
ColliderList.Clear(); results.Clear();
for (int i = 0; i < triggerCount; i++) for (int i = 0; i < triggerCount; i++)
ColliderList.Add(nonAllocResults[i]); results.Add(nonAllocResults[i]);
OnTriggeredCollidersUpdated?.Invoke(ColliderList); OnTriggeredCollidersUpdated?.Invoke(results);
} }
previousTriggerCount = triggerCount; previousTriggerCount = triggerCount;

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger namespace Syntriax.Modules.Trigger
{ {
public interface IColliderTriggerArea : ITriggerArea public interface IColliderTrigger : ITriggerArea
{ {
/// <summary> /// <summary>
/// <see cref="LayerMask"/> value for checking triggers /// <see cref="LayerMask"/> value for checking triggers
@ -14,10 +14,7 @@ namespace Syntriax.Modules.Trigger
/// <summary> /// <summary>
/// Called whenever the list of <see cref="Collider2D"/> changes /// Called whenever the list of <see cref="Collider2D"/> changes
/// </summary> /// </summary>
/// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></value> /// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTrigger"/></value>
Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; }
/// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></value>
List<Collider2D> ColliderList { get; }
} }
} }

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: efbbfd3aba8fb5843a26ed5446050b32 guid: a101e5476051bb74b8012198b1594327
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -1,6 +1,6 @@
{ {
"name": "com.syntriax.trigger", "name": "com.syntriax.trigger",
"version": "0.4.0", "version": "0.3.0",
"displayName": "Trigger Module", "displayName": "Trigger Module",
"unity": "2019.1", "unity": "2019.1",
"documentationUrl": "https://git.syntriax.com/Syntriax/Trigger.git", "documentationUrl": "https://git.syntriax.com/Syntriax/Trigger.git",