1
0
mirror of https://projects.caleb-brown.dev/UDRI-XRT/UDRIGEEKCup2024.git synced 2025-01-22 15:18:25 -05:00
UDRIGEEKCup2024/Assets/Scripts/OnColliderTrigger.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2024-04-17 12:30:02 -04:00
using System.Collections.Generic;
using UnityAtoms.BaseAtoms;
using UnityEngine;
using UnityEngine.Events;
2024-04-17 12:30:02 -04:00
using UnityAtoms.Tags;
namespace MAVRIC.GEEKCup
{
[RequireComponent(typeof(Collider))]
2024-04-16 15:49:32 -04:00
public class OnColliderTrigger : MonoBehaviour
{
2024-04-16 16:23:46 -04:00
public bool invertResult = false;
// TODO: Update this to use a UnityAtoms BoolReference
[SerializeField] private UnityEvent<bool> onTrigger;
2024-04-17 12:30:02 -04:00
[SerializeField] private LayerMask layerMask = 1 >> 0;
[SerializeField] private List<StringConstant> tagsMask = new ();
private void OnTriggerEnter(Collider other)
{
2024-04-17 12:30:02 -04:00
// if ((1 << other.gameObject.layer & layerMask) == 0) return;
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
Debug.Log($"HasValidTags: {hasValidTags}");
if (hasValidTags)
{
2024-04-17 12:30:02 -04:00
var result = invertResult ? false : true;
Debug.Log(result);
onTrigger?.Invoke(result);
}
}
private void OnTriggerExit(Collider other)
{
2024-04-17 12:30:02 -04:00
var hasValidTags = other.gameObject.HasAnyTag(tagsMask);
Debug.Log($"HasValidTags: {hasValidTags}");
if (hasValidTags)
{
2024-04-17 12:30:02 -04:00
var result = invertResult ? true : false;
Debug.Log($"Result: {result}");
onTrigger?.Invoke(result);
}
}
}
}