mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Assembling Main scene.
This commit is contained in:
17
Assets/Scripts/ConstantRotation.cs
Normal file
17
Assets/Scripts/ConstantRotation.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ConstantRotation: MonoBehaviour
|
||||
{
|
||||
public Vector3 Axis = Vector3.up;
|
||||
|
||||
public float RotationRate = 1f;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
var rotation = transform.rotation;
|
||||
|
||||
var delta = Quaternion.AngleAxis(RotationRate * Time.deltaTime, Axis);
|
||||
|
||||
transform.SetPositionAndRotation(transform.position, rotation * delta);
|
||||
}
|
||||
}
|
3
Assets/Scripts/ConstantRotation.cs.meta
Normal file
3
Assets/Scripts/ConstantRotation.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9aaa57bc45674fb790590777dfe23cb4
|
||||
timeCreated: 1723985243
|
3
Assets/Scripts/Interactable.meta
Normal file
3
Assets/Scripts/Interactable.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98b2ed3a0efd45ea919595f3f1e83012
|
||||
timeCreated: 1723987686
|
25
Assets/Scripts/Interactable/HammerRepair.cs
Normal file
25
Assets/Scripts/Interactable/HammerRepair.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Nothke.Interaction;
|
||||
using Nothke.Interaction.Items;
|
||||
using UnityEngine;
|
||||
|
||||
public class HammerRepair: Interactable
|
||||
{
|
||||
public override void Use(InteractionController im)
|
||||
{
|
||||
if (im.hands.item == null)
|
||||
{
|
||||
base.Use(im);
|
||||
return;
|
||||
}
|
||||
|
||||
var product = GetComponentInChildren<Product>();
|
||||
|
||||
if (!product)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var clip = product.Type.SelectClip(product.Defect != DefectType.None);
|
||||
NAudio.Play(clip, transform.position);
|
||||
}
|
||||
}
|
3
Assets/Scripts/Interactable/HammerRepair.cs.meta
Normal file
3
Assets/Scripts/Interactable/HammerRepair.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bde7b42f7560494da2171ea528381467
|
||||
timeCreated: 1723989068
|
25
Assets/Scripts/Interactable/HammerableRigidbody.cs
Normal file
25
Assets/Scripts/Interactable/HammerableRigidbody.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Nothke.Interaction;
|
||||
using Nothke.Interaction.Items;
|
||||
using UnityEngine;
|
||||
|
||||
public class HammerableRigidbody: RigidbodyInteractable
|
||||
{
|
||||
public override void Use(InteractionController im)
|
||||
{
|
||||
if (im.hands.item == null)
|
||||
{
|
||||
base.Use(im);
|
||||
return;
|
||||
}
|
||||
|
||||
var product = GetComponentInChildren<Product>();
|
||||
|
||||
if (!product)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var clip = product.Type.SelectClip(product.Defect != DefectType.None);
|
||||
NAudio.Play(clip, transform.position);
|
||||
}
|
||||
}
|
3
Assets/Scripts/Interactable/HammerableRigidbody.cs.meta
Normal file
3
Assets/Scripts/Interactable/HammerableRigidbody.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f1ba88558d742b9a6f1c78794058aba
|
||||
timeCreated: 1723987695
|
@@ -10,8 +10,10 @@ public class Converter: MonoBehaviour
|
||||
public Transform outputPoint;
|
||||
public ProductType conversionProduct;
|
||||
|
||||
public bool isBroken;
|
||||
public float conversionTime = 5f;
|
||||
public int CurrentHealth;
|
||||
public int MaxHealth;
|
||||
|
||||
public float conversionDuration = 5f;
|
||||
private float _conversionTimer;
|
||||
|
||||
public Transform refuseLauncher;
|
||||
@@ -28,9 +30,15 @@ public class Converter: MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_conversionTimer = conversionDuration;
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (isBroken)
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -56,7 +64,7 @@ public class Converter: MonoBehaviour
|
||||
inputProducts.RemoveAt(0);
|
||||
}
|
||||
|
||||
_conversionTimer = conversionTime;
|
||||
_conversionTimer = conversionDuration;
|
||||
}
|
||||
|
||||
_conversionTimer -= Time.deltaTime;
|
||||
|
@@ -9,18 +9,11 @@ public class ProductReceiver : MonoBehaviour
|
||||
public int normalProductCount;
|
||||
public int defectiveProductCount;
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
private void OnTriggerEnter(Collider otherCollider)
|
||||
{
|
||||
var rb = collision.rigidbody;
|
||||
var product = otherCollider.GetComponentInParent<Product>();
|
||||
|
||||
if (!rb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//enteredBodies.Add(rb);
|
||||
|
||||
if (rb.TryGetComponent(out Product product))
|
||||
if (product != null)
|
||||
{
|
||||
if (product.Defect != DefectType.None)
|
||||
{
|
||||
@@ -31,7 +24,7 @@ public class ProductReceiver : MonoBehaviour
|
||||
normalProductCount++;
|
||||
}
|
||||
|
||||
Destroy(rb.gameObject);
|
||||
Destroy(product.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -5,45 +5,28 @@ 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> _knownProducts;
|
||||
|
||||
public AudioClip goodSound;
|
||||
public AudioClip badSound;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent(out Product product))
|
||||
var product = other.GetComponentInParent<Product>();
|
||||
|
||||
if (product == null)
|
||||
{
|
||||
if (_knownProducts.Contains(product))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_knownProducts.Add(product);
|
||||
|
||||
if (product.Defect == DefectType.None)
|
||||
{
|
||||
var falseNegativeRoll = Random.Range(0, 100);
|
||||
|
||||
if (falseNegativeRoll > FalseNegativeChance)
|
||||
{
|
||||
AlarmEvent.Invoke();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var falsePositiveRoll = Random.Range(0, 100);
|
||||
|
||||
if (falsePositiveRoll < FalsePositiveChance)
|
||||
{
|
||||
AlarmEvent.Invoke();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (_knownProducts.Contains(product))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_knownProducts.Add(product);
|
||||
|
||||
NAudio.Play(product.Defect == DefectType.None ? goodSound : badSound, transform.position);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
|
@@ -1,10 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DefectMaterialVisualizer: MonoBehaviour, IDefectVisualizer
|
||||
public class DefectMaterialVisualizer : MonoBehaviour, IDefectVisualizer
|
||||
{
|
||||
public MeshRenderer MeshRenderer;
|
||||
|
||||
|
||||
private List<DefectType> supportedDefects = new()
|
||||
{
|
||||
DefectType.Hex_MissingMaterial_1,
|
||||
@@ -13,17 +13,19 @@ public class DefectMaterialVisualizer: MonoBehaviour, IDefectVisualizer
|
||||
DefectType.Hex_MissingMaterial_4,
|
||||
DefectType.Hex_MissingMaterial_5,
|
||||
};
|
||||
|
||||
|
||||
public void VisualizeDefect(DefectType defectType)
|
||||
{
|
||||
var materials = MeshRenderer.sharedMaterials;
|
||||
|
||||
for (var i = 0; i < supportedDefects.Count; i++)
|
||||
{
|
||||
if (!defectType.HasFlag(supportedDefects[i]))
|
||||
if (defectType.HasFlag(supportedDefects[i]))
|
||||
{
|
||||
continue;
|
||||
materials[i + 1] = null;
|
||||
}
|
||||
|
||||
MeshRenderer.materials[i] = GameAssets.Instance.MissingMaterial;
|
||||
}
|
||||
|
||||
MeshRenderer.sharedMaterials = materials;
|
||||
}
|
||||
}
|
@@ -15,6 +15,9 @@ public class ProductType : ScriptableObject
|
||||
public int Probability;
|
||||
}
|
||||
|
||||
public AudioClip[] normalClips;
|
||||
public AudioClip[] defectiveClips;
|
||||
|
||||
public DefectProbability[] DefectProbabilities;
|
||||
|
||||
public static void SpawnProduct(ProductType type, Transform origin)
|
||||
@@ -42,4 +45,13 @@ public class ProductType : ScriptableObject
|
||||
|
||||
return DefectType.None;
|
||||
}
|
||||
|
||||
public AudioClip SelectClip(bool defective)
|
||||
{
|
||||
var clips = defective ? defectiveClips : normalClips;
|
||||
|
||||
int index = Random.Range(0, clips.Length);
|
||||
|
||||
return clips[index];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user