2019-10-15 19:43:51 -04:00
using UnityEngine ;
namespace UnityAtoms.MonoHooks
{
/// <summary>
/// Mono Hook for [`OnTriggerEnter2D`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerEnter2D.html), [`OnTriggerExit2D`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerExit2D.html) and [`OnTriggerStay2D`](https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnTriggerStay2D.html)
/// </summary>
[EditorIcon("atom-icon-delicate")]
2019-11-13 02:59:39 -05:00
[AddComponentMenu("Unity Atoms/Hooks/On Trigger 2D Hook")]
2019-10-15 19:43:51 -04:00
public sealed class OnTrigger2DHook : Collider2DHook
{
/// <summary>
/// Set to true if Event should be triggered on `OnTriggerEnter2D`
/// </summary>
[SerializeField]
2019-10-20 15:16:07 -04:00
private bool _triggerOnEnter = default ( bool ) ;
2019-10-15 19:43:51 -04:00
/// <summary>
/// Set to true if Event should be triggered on `OnTriggerExit2D`
/// </summary>
[SerializeField]
2019-10-20 15:16:07 -04:00
private bool _triggerOnExit = default ( bool ) ;
2019-10-15 19:43:51 -04:00
/// <summary>
/// Set to true if Event should be triggered on `OnTriggerStay2D`
/// </summary>
[SerializeField]
2019-10-20 15:16:07 -04:00
private bool _triggerOnStay = default ( bool ) ;
2019-10-15 19:43:51 -04:00
private void OnTriggerEnter2D ( Collider2D other )
{
if ( _triggerOnEnter ) OnHook ( other ) ;
}
private void OnTriggerExit2D ( Collider2D other )
{
if ( _triggerOnExit ) OnHook ( other ) ;
}
private void OnTriggerStay2D ( Collider2D other )
{
if ( _triggerOnStay ) OnHook ( other ) ;
}
}
}