mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-09 07:13:42 +00:00
Reworking item spawn, adding item conversion.
This commit is contained in:
74
Assets/Scripts/Machines/ProductConverter.cs
Normal file
74
Assets/Scripts/Machines/ProductConverter.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Converter: MonoBehaviour
|
||||
{
|
||||
public List<Product> inputProducts;
|
||||
|
||||
public ProductType expectedReagent;
|
||||
public Transform outputPoint;
|
||||
public ProductType conversionProduct;
|
||||
|
||||
public bool isBroken;
|
||||
public float conversionTime = 5f;
|
||||
private float _conversionTimer;
|
||||
|
||||
public Transform refuseLauncher;
|
||||
public float launchPower = 10f;
|
||||
|
||||
public void OnTriggerEnter(Collider other)
|
||||
{
|
||||
var product = other.GetComponentInParent<Product>();
|
||||
|
||||
if (product)
|
||||
{
|
||||
product.gameObject.SetActive(false);
|
||||
inputProducts.Add(product);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (isBroken)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (inputProducts.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_conversionTimer <= 0f)
|
||||
{
|
||||
var currentProduct = inputProducts[0];
|
||||
|
||||
if (inputProducts[0].Type == expectedReagent)
|
||||
{
|
||||
ProductType.SpawnProduct(conversionProduct, outputPoint);
|
||||
inputProducts.RemoveAt(0);
|
||||
Destroy(currentProduct);
|
||||
}
|
||||
else
|
||||
{
|
||||
Expel(inputProducts[0]);
|
||||
inputProducts.RemoveAt(0);
|
||||
}
|
||||
|
||||
_conversionTimer = conversionTime;
|
||||
}
|
||||
|
||||
_conversionTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
private void Expel(Product product)
|
||||
{
|
||||
product.transform.position = refuseLauncher.position;
|
||||
product.transform.rotation = refuseLauncher.rotation;
|
||||
|
||||
product.gameObject.SetActive(true);
|
||||
|
||||
product.GetComponent<Rigidbody>().velocity = launchPower * refuseLauncher.forward;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Machines/ProductConverter.cs.meta
Normal file
3
Assets/Scripts/Machines/ProductConverter.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 648bc447374048b0a38c2369cbb3939e
|
||||
timeCreated: 1723978325
|
@@ -19,16 +19,19 @@ public class ProductReceiver : MonoBehaviour
|
||||
}
|
||||
|
||||
//enteredBodies.Add(rb);
|
||||
|
||||
if (rb.GetComponent<DefectiveProduct>())
|
||||
|
||||
if (rb.TryGetComponent(out Product product))
|
||||
{
|
||||
defectiveProductCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
normalProductCount++;
|
||||
}
|
||||
if (product.Defect != DefectType.None)
|
||||
{
|
||||
defectiveProductCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
normalProductCount++;
|
||||
}
|
||||
|
||||
Destroy(rb.gameObject);
|
||||
Destroy(rb.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ public class ProductSpawner : MonoBehaviour
|
||||
public struct ProductionPhase
|
||||
{
|
||||
public ProductionPhaseType Type;
|
||||
public ProductDescription Description;
|
||||
public ProductType ProductType;
|
||||
[Min(1f)]
|
||||
public float Duration;
|
||||
[Min(1f)]
|
||||
@@ -62,7 +62,7 @@ public class ProductSpawner : MonoBehaviour
|
||||
|
||||
_spawnTimer = currentPhase.SpawnInterval;
|
||||
|
||||
Instantiate(currentPhase.Description.GetRandomProduct(), transform.position, Quaternion.identity);
|
||||
ProductType.SpawnProduct(currentPhase.ProductType, transform);
|
||||
}
|
||||
|
||||
if (_remainingDuration <= 0)
|
||||
|
@@ -12,20 +12,20 @@ public class StationaryDefectDetector : MonoBehaviour
|
||||
[Range(0, 100)]
|
||||
public int FalseNegativeChance;
|
||||
|
||||
public List<Product> _detectedDefects;
|
||||
public List<Product> _knownProducts;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent(out Product product))
|
||||
{
|
||||
if (_detectedDefects.Contains(product))
|
||||
if (_knownProducts.Contains(product))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_detectedDefects.Add(product);
|
||||
_knownProducts.Add(product);
|
||||
|
||||
if (other.TryGetComponent(out DefectiveProduct defectiveProduct))
|
||||
if (product.Defect == DefectType.None)
|
||||
{
|
||||
var falseNegativeRoll = Random.Range(0, 100);
|
||||
|
||||
@@ -48,11 +48,11 @@ public class StationaryDefectDetector : MonoBehaviour
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.TryGetComponent(out DefectiveProduct product))
|
||||
if (other.TryGetComponent(out Product product))
|
||||
{
|
||||
if (_detectedDefects.Contains(product))
|
||||
if (_knownProducts.Contains(product))
|
||||
{
|
||||
_detectedDefects.Remove(product);
|
||||
_knownProducts.Remove(product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,14 +24,16 @@ public class TrashBin : MonoBehaviour
|
||||
|
||||
public void OnTriggerEnter(Collider otherCollider)
|
||||
{
|
||||
var rb = otherCollider.GetComponent<Rigidbody>();
|
||||
var rb = otherCollider.GetComponentInParent<Rigidbody>();
|
||||
|
||||
if (!rb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherCollider.TryGetComponent(out Product product))
|
||||
var product = otherCollider.GetComponentInParent<Product>();
|
||||
|
||||
if (product)
|
||||
{
|
||||
if (!enteredProducts.Contains(product))
|
||||
{
|
||||
@@ -45,7 +47,9 @@ public class TrashBin : MonoBehaviour
|
||||
|
||||
public void OnTriggerExit(Collider collider)
|
||||
{
|
||||
if (collider.TryGetComponent(out Product product))
|
||||
var product = collider.GetComponentInParent<Product>();
|
||||
|
||||
if (product)
|
||||
{
|
||||
if (enteredProducts.Contains(product))
|
||||
{
|
||||
|
Reference in New Issue
Block a user