2024-04-17 12:30:02 -04:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityAtoms.BaseAtoms;
|
2024-04-16 11:17:09 -04:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
2024-04-17 12:30:02 -04:00
|
|
|
using UnityAtoms.Tags;
|
2024-04-16 11:17:09 -04:00
|
|
|
|
|
|
|
namespace MAVRIC.GEEKCup
|
|
|
|
{
|
2024-04-16 14:11:13 -04:00
|
|
|
[RequireComponent(typeof(Collider))]
|
2024-04-16 15:49:32 -04:00
|
|
|
public class OnColliderTrigger : MonoBehaviour
|
2024-04-16 11:17:09 -04:00
|
|
|
{
|
2024-04-16 16:23:46 -04:00
|
|
|
public bool invertResult = false;
|
2024-04-16 14:11:13 -04:00
|
|
|
|
2024-04-16 11:17:09 -04:00
|
|
|
// 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 ();
|
2024-04-16 11:17:09 -04:00
|
|
|
|
|
|
|
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-16 11:17:09 -04:00
|
|
|
{
|
2024-04-17 12:30:02 -04:00
|
|
|
var result = invertResult ? false : true;
|
|
|
|
Debug.Log(result);
|
|
|
|
onTrigger?.Invoke(result);
|
2024-04-16 11:17:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-16 11:17:09 -04:00
|
|
|
{
|
2024-04-17 12:30:02 -04:00
|
|
|
var result = invertResult ? true : false;
|
|
|
|
Debug.Log($"Result: {result}");
|
|
|
|
onTrigger?.Invoke(result);
|
2024-04-16 11:17:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|