mirror of
https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git
synced 2025-01-22 07:08:51 -05:00
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using UnityAtoms.BaseAtoms;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityAtoms.Tags;
|
|
|
|
namespace MAVRIC.GEEKCup
|
|
{
|
|
[RequireComponent(typeof(Collider))]
|
|
public class OnColliderTrigger : MonoBehaviour
|
|
{
|
|
public bool invertResult = false;
|
|
|
|
// TODO: Update this to use a UnityAtoms BoolReference
|
|
[SerializeField] private UnityEvent<bool> onTrigger;
|
|
|
|
[SerializeField] private LayerMask layerMask = 1 >> 0;
|
|
[SerializeField] private List<StringConstant> tagsMask = new List<StringConstant>();
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
// if ((1 << other.gameObject.layer & layerMask) == 0) return;
|
|
|
|
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
|
|
Debug.Log($"HasValidTags: {hasValidTags}");
|
|
|
|
if (hasValidTags)
|
|
{
|
|
var result = invertResult ? false : true;
|
|
Debug.Log(result);
|
|
onTrigger?.Invoke(result);
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
|
|
Debug.Log($"HasValidTags: {hasValidTags}");
|
|
|
|
if (hasValidTags)
|
|
{
|
|
var result = invertResult ? true : false;
|
|
Debug.Log($"Result: {result}");
|
|
onTrigger?.Invoke(result);
|
|
}
|
|
}
|
|
}
|
|
} |