Compare commits
No commits in common. "25edbb5e3760422025f02abe0835b68fb6e4fd97" and "1cc02b2c926e31ea98df711b608a189fc7a60ae1" have entirely different histories.
25edbb5e37
...
1cc02b2c92
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Syntriax.Modules.ToggleState;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTrigger : Trigger, IColliderTrigger
|
||||
{
|
||||
[SerializeField] private LayerMask colliderMask = 0;
|
||||
|
||||
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
|
||||
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
|
||||
|
||||
private Collider2D[] nonAllocResults = new Collider2D[32];
|
||||
public List<Collider2D> results = new List<Collider2D>(32);
|
||||
|
||||
private int previousTriggerCount = 0;
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (!ToggleStateMember.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
int triggerCount = Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocResults, ColliderMask);
|
||||
|
||||
if (triggerCount == previousTriggerCount)
|
||||
return;
|
||||
previousTriggerCount = triggerCount;
|
||||
|
||||
results.Clear();
|
||||
for (int i = 0; i < triggerCount; i++)
|
||||
results.Add(nonAllocResults[i]);
|
||||
|
||||
IsTrigerred = triggerCount > 0;
|
||||
OnTriggeredCollidersUpdated?.Invoke(results);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = IsTrigerred ? Color.green : Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d9e5082ab403a7240a6bf0554a93518f
|
||||
guid: 20a6baf9a256917448a4d7ad09d0c51a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Syntriax.Modules.ToggleState;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTriggerWithRotation : Trigger, IColliderTrigger
|
||||
{
|
||||
[SerializeField] private LayerMask colliderMask = 0;
|
||||
|
||||
public LayerMask ColliderMask { get => colliderMask; set => colliderMask = value; }
|
||||
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
|
||||
|
||||
private Collider2D[] nonAllocResults = new Collider2D[32];
|
||||
public List<Collider2D> results = new List<Collider2D>(32);
|
||||
|
||||
private int previousTriggerCount = 0;
|
||||
|
||||
protected void FixedUpdate()
|
||||
{
|
||||
if (!ToggleStateMember.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
int triggerCount = Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, transform.rotation.eulerAngles.z, nonAllocResults, ColliderMask);
|
||||
|
||||
if (triggerCount == previousTriggerCount)
|
||||
return;
|
||||
previousTriggerCount = triggerCount;
|
||||
|
||||
results.Clear();
|
||||
for (int i = 0; i < triggerCount; i++)
|
||||
results.Add(nonAllocResults[i]);
|
||||
|
||||
IsTrigerred = triggerCount > 0;
|
||||
OnTriggeredCollidersUpdated?.Invoke(results);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = IsTrigerred ? Color.green : Color.red;
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b2d9ae6bcc3b69a4093f8c740f040229
|
||||
guid: e56ea33695c0c83438ea8b7bf11d1cf8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09a25591637cbdf45ad71415d94bf641
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,18 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTriggerArea : ColliderTriggerAreaBase
|
||||
{
|
||||
protected override int TriggerCount
|
||||
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, 0, nonAllocResults, ColliderMask);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
|
||||
Gizmos.DrawWireCube(transform.position, transform.lossyScale);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DColliderTriggerAreaWithRotation : ColliderTriggerAreaBase
|
||||
{
|
||||
protected override int TriggerCount
|
||||
=> Physics2D.OverlapBoxNonAlloc(transform.position, transform.localScale, transform.rotation.eulerAngles.z, nonAllocResults, ColliderMask);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.color = previousTriggerCount > 0 ? Color.green : Color.red;
|
||||
Gizmos.matrix = transform.localToWorldMatrix;
|
||||
Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
using Syntriax.Modules.ToggleState;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class ColliderTrigger : TriggerBase
|
||||
{
|
||||
protected IColliderTrigger colliderTrigger = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
colliderTrigger = GetComponent<IColliderTrigger>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!ToggleStateMember.IsToggledNullChecked())
|
||||
return;
|
||||
|
||||
IsTrigerred = colliderTrigger.Check();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public abstract class ColliderTriggerAreaBase : MonoBehaviour, IColliderTrigger
|
||||
{
|
||||
protected List<Collider2D> results = new List<Collider2D>(32);
|
||||
|
||||
protected Collider2D[] nonAllocResults = new Collider2D[32];
|
||||
protected int previousTriggerCount = 0;
|
||||
|
||||
public LayerMask ColliderMask { get; set; } = ~0;
|
||||
public Action<List<Collider2D>> OnTriggeredCollidersUpdated { get; set; } = null;
|
||||
|
||||
protected abstract int TriggerCount { get; }
|
||||
|
||||
public virtual bool Check()
|
||||
{
|
||||
int triggerCount = TriggerCount;
|
||||
|
||||
if (triggerCount != previousTriggerCount)
|
||||
{
|
||||
results.Clear();
|
||||
for (int i = 0; i < triggerCount; i++)
|
||||
results.Add(nonAllocResults[i]);
|
||||
|
||||
OnTriggeredCollidersUpdated?.Invoke(results);
|
||||
}
|
||||
|
||||
previousTriggerCount = triggerCount;
|
||||
return triggerCount > 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DGroundTriggerArea : Box2DColliderTriggerArea, IGroundTriggerArea { }
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b3db9faa3a5e9f4db37172c452dbf2a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,4 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DGroundTriggerAreaWithRotation : Box2DColliderTriggerAreaWithRotation, IGroundTriggerArea { }
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dbb4ef661e6f9fc4fb8584059bc8e5cc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,4 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class GroundTrigger : ColliderTrigger, IGroundTrigger { }
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 91a5b9cf888de6f4da572ac875fc826c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,4 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public interface IGroundTrigger : ITrigger { }
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public interface IGroundTriggerArea : ITriggerArea { }
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a6e6150c32aa1f4d87db161c5fb65db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,11 +0,0 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public interface ITriggerArea
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if the <see cref="ITriggerArea"/> is Triggered
|
||||
/// </summary>
|
||||
/// <returns>true if <see cref="ITriggerArea"/> is triggered, false if not</returns>
|
||||
bool Check();
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d8fff127b37aecc4495535a383f8f4bf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,4 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DGroundTrigger : Box2DColliderTrigger, IGroundTrigger { }
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 13b8a72003d46b24fa2e67093c42c49d
|
||||
guid: 7804f3e8384c7a54482f585b4f43264a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -0,0 +1,4 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class Box2DGroundTriggerWithRotation : Box2DColliderTriggerWithRotation, IGroundTrigger { }
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7302d5358a0cd4a4c9a2c8dd9a4a7697
|
||||
guid: d8b544fd215b0df4192a7889e6f2db4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -0,0 +1,4 @@
|
|||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public interface IGroundTrigger : IColliderTrigger { }
|
||||
}
|
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public interface IColliderTrigger : ITriggerArea
|
||||
public interface IColliderTrigger : ITrigger
|
||||
{
|
||||
/// <summary>
|
||||
/// <see cref="LayerMask"/> value for checking triggers
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a101e5476051bb74b8012198b1594327
|
||||
guid: e199ccade2250b646abfd859e4aa1e7a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
|
@ -15,7 +15,6 @@ namespace Syntriax.Modules.Trigger
|
|||
/// </summary>
|
||||
/// <value>The new value of IsTrigerred</value>
|
||||
Action<bool> OnTriggerStateChanged { get; set; }
|
||||
|
||||
bool IsTrigerred { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,11 @@ namespace Syntriax.Modules.Trigger
|
|||
public static class ITriggerExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks if the provided parameter <see cref="ITrigger"/> is toggled, if the parameter is null returns the nullValue parameter
|
||||
/// Checks if the provided parameter ITrigger is toggled, if the parameter is null returns the nullValue parameter
|
||||
/// </summary>
|
||||
/// <param name="trigger"><see cref="ITrigger"/> to be checked if toggled or not</param>
|
||||
/// <param name="nullValue">The value that will be returned if trigger is null. Default value: true</param>
|
||||
/// <returns><see cref="ITrigger"/>'s toggle value, or if null return nullValue parameter</returns>
|
||||
/// <param name="trigger">ITrigger to be checked if toggled or not</param>
|
||||
/// <param name="nullValue">The value that will be returned if toggleState is null. Default value: true</param>
|
||||
/// <returns>ITrigger's toggle value, or if null return nullValue parameter</returns>
|
||||
public static bool IsTriggeredNullChecked(this ITrigger trigger, bool nullValue = true)
|
||||
=> trigger == null ? nullValue : trigger.IsTrigerred;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ using UnityEngine;
|
|||
|
||||
namespace Syntriax.Modules.Trigger
|
||||
{
|
||||
public class TriggerBase : MonoBehaviour, ITrigger
|
||||
public class Trigger : MonoBehaviour, ITrigger
|
||||
{
|
||||
public IToggleState ToggleStateMember { get; protected set; } = new ToggleStateMember(true);
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1e3718079b1e1024a997ca7eaa425903
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,11 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f28f409248975dc4fb1d9e01e88ea65e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "com.syntriax.trigger",
|
||||
"version": "0.3.0",
|
||||
"version": "0.2.0",
|
||||
"displayName": "Trigger Module",
|
||||
"unity": "2019.1",
|
||||
"documentationUrl": "https://git.syntriax.com/Syntriax/Trigger.git",
|
||||
|
|
Loading…
Reference in New Issue