2024-08-17 19:07:25 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
public class StationaryDefectDetector : MonoBehaviour
|
|
|
|
{
|
|
|
|
public UnityEvent AlarmEvent;
|
|
|
|
|
|
|
|
[Range(0, 100)]
|
|
|
|
public int FalsePositiveChance;
|
|
|
|
[Range(0, 100)]
|
|
|
|
public int FalseNegativeChance;
|
|
|
|
|
2024-08-18 12:44:44 +00:00
|
|
|
public List<Product> _knownProducts;
|
2024-08-17 19:07:25 +00:00
|
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
if (other.TryGetComponent(out Product product))
|
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
if (_knownProducts.Contains(product))
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-18 12:44:44 +00:00
|
|
|
_knownProducts.Add(product);
|
2024-08-17 19:07:25 +00:00
|
|
|
|
2024-08-18 12:44:44 +00:00
|
|
|
if (product.Defect == DefectType.None)
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
|
|
|
var falseNegativeRoll = Random.Range(0, 100);
|
|
|
|
|
|
|
|
if (falseNegativeRoll > FalseNegativeChance)
|
|
|
|
{
|
|
|
|
AlarmEvent.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var falsePositiveRoll = Random.Range(0, 100);
|
|
|
|
|
|
|
|
if (falsePositiveRoll < FalsePositiveChance)
|
|
|
|
{
|
|
|
|
AlarmEvent.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
if (other.TryGetComponent(out Product product))
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
if (_knownProducts.Contains(product))
|
2024-08-17 19:07:25 +00:00
|
|
|
{
|
2024-08-18 12:44:44 +00:00
|
|
|
_knownProducts.Remove(product);
|
2024-08-17 19:07:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|