Compare commits

...

3 Commits

Author SHA1 Message Date
Syntriax ac1cdfec18 0.4.0 2022-12-17 14:58:10 +03:00
Syntriax 3ccaea0434 Merge branch 'development' 2022-12-17 14:57:32 +03:00
Syntriax 1b0d568a05 ColliderList field to ITrigger & Name Fix 2022-12-17 14:57:18 +03:00
5 changed files with 14 additions and 12 deletions

View File

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

View File

@ -4,15 +4,14 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger namespace Syntriax.Modules.Trigger
{ {
public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTrigger public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTriggerArea
{ {
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; }
@ -22,11 +21,11 @@ namespace Syntriax.Modules.Trigger
if (triggerCount != previousTriggerCount) if (triggerCount != previousTriggerCount)
{ {
results.Clear(); ColliderList.Clear();
for (int i = 0; i < triggerCount; i++) for (int i = 0; i < triggerCount; i++)
results.Add(nonAllocResults[i]); ColliderList.Add(nonAllocResults[i]);
OnTriggeredCollidersUpdated?.Invoke(results); OnTriggeredCollidersUpdated?.Invoke(ColliderList);
} }
previousTriggerCount = triggerCount; previousTriggerCount = triggerCount;

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace Syntriax.Modules.Trigger namespace Syntriax.Modules.Trigger
{ {
public interface IColliderTrigger : ITriggerArea public interface IColliderTriggerArea : ITriggerArea
{ {
/// <summary> /// <summary>
/// <see cref="LayerMask"/> value for checking triggers /// <see cref="LayerMask"/> value for checking triggers
@ -14,7 +14,10 @@ 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="IColliderTrigger"/></value> /// <value>List of <see cref="Collider2D"/> that triggered the <see cref="IColliderTriggerArea"/></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: a101e5476051bb74b8012198b1594327 guid: efbbfd3aba8fb5843a26ed5446050b32
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -1,6 +1,6 @@
{ {
"name": "com.syntriax.trigger", "name": "com.syntriax.trigger",
"version": "0.3.0", "version": "0.4.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",