mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-09 07:13:42 +00:00
Added defect detector prefab.
This commit is contained in:
13
Assets/Scripts/Machines/AudioAlarm.cs
Normal file
13
Assets/Scripts/Machines/AudioAlarm.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AudioAlarm : MonoBehaviour
|
||||
{
|
||||
public float Duration;
|
||||
|
||||
private bool _isPlaying;
|
||||
|
||||
public void PlayAlarm()
|
||||
{
|
||||
Debug.Log("Playing alarm");
|
||||
}
|
||||
}
|
3
Assets/Scripts/Machines/AudioAlarm.cs.meta
Normal file
3
Assets/Scripts/Machines/AudioAlarm.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c996d1be4ecb4e8d92bc4344f7f98854
|
||||
timeCreated: 1723921340
|
59
Assets/Scripts/Machines/StationaryDefectDetector.cs
Normal file
59
Assets/Scripts/Machines/StationaryDefectDetector.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
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;
|
||||
|
||||
public List<Product> _detectedDefects;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent(out Product product))
|
||||
{
|
||||
if (_detectedDefects.Contains(product))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_detectedDefects.Add(product);
|
||||
|
||||
if (other.TryGetComponent(out DefectiveProduct defectiveProduct))
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (other.TryGetComponent(out DefectiveProduct product))
|
||||
{
|
||||
if (_detectedDefects.Contains(product))
|
||||
{
|
||||
_detectedDefects.Remove(product);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Machines/StationaryDefectDetector.cs.meta
Normal file
3
Assets/Scripts/Machines/StationaryDefectDetector.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e00ad13b6427460abe6c3aec6566b6e5
|
||||
timeCreated: 1723920624
|
Reference in New Issue
Block a user