mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Merge branch 'master' of https://github.com/nothke/quality-control
This commit is contained in:
16
Assets/Scripts/GameAssets.cs
Normal file
16
Assets/Scripts/GameAssets.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GameAssets: MonoBehaviour
|
||||
{
|
||||
public static GameAssets Instance;
|
||||
|
||||
public Material MissingMaterial;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/GameAssets.cs.meta
Normal file
3
Assets/Scripts/GameAssets.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea024824a29348d580d9e07817800c84
|
||||
timeCreated: 1723978793
|
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))
|
||||
{
|
||||
|
16
Assets/Scripts/Products/DefectEnum.cs
Normal file
16
Assets/Scripts/Products/DefectEnum.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
[Flags]
|
||||
public enum DefectType
|
||||
{
|
||||
None = 0,
|
||||
|
||||
Hex_MissingMaterial_1 = 1 << 0,
|
||||
Hex_MissingMaterial_2 = 1 << 1,
|
||||
Hex_MissingMaterial_3 = 1 << 2,
|
||||
Hex_MissingMaterial_4 = 1 << 3,
|
||||
Hex_MissingMaterial_5 = 1 << 4,
|
||||
|
||||
E_No_Cutout = 1 << 10,
|
||||
E_Made_6 = 1 << 11,
|
||||
}
|
3
Assets/Scripts/Products/DefectEnum.cs.meta
Normal file
3
Assets/Scripts/Products/DefectEnum.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e48fe9fec9d04b89a7d3e8878e55a054
|
||||
timeCreated: 1723978865
|
29
Assets/Scripts/Products/DefectMaterialVisualizer.cs
Normal file
29
Assets/Scripts/Products/DefectMaterialVisualizer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DefectMaterialVisualizer: MonoBehaviour, IDefectVisualizer
|
||||
{
|
||||
public MeshRenderer MeshRenderer;
|
||||
|
||||
private List<DefectType> supportedDefects = new()
|
||||
{
|
||||
DefectType.Hex_MissingMaterial_1,
|
||||
DefectType.Hex_MissingMaterial_2,
|
||||
DefectType.Hex_MissingMaterial_3,
|
||||
DefectType.Hex_MissingMaterial_4,
|
||||
DefectType.Hex_MissingMaterial_5,
|
||||
};
|
||||
|
||||
public void VisualizeDefect(DefectType defectType)
|
||||
{
|
||||
for (var i = 0; i < supportedDefects.Count; i++)
|
||||
{
|
||||
if (!defectType.HasFlag(supportedDefects[i]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
MeshRenderer.materials[i] = GameAssets.Instance.MissingMaterial;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Products/DefectMaterialVisualizer.cs.meta
Normal file
3
Assets/Scripts/Products/DefectMaterialVisualizer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1432478c6b38458188a508ec961872f2
|
||||
timeCreated: 1723979252
|
45
Assets/Scripts/Products/DefectMeshSelector.cs
Normal file
45
Assets/Scripts/Products/DefectMeshSelector.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DefectMeshSelector: MonoBehaviour, IDefectVisualizer
|
||||
{
|
||||
public GameObject NormalPrefab;
|
||||
|
||||
[Serializable]
|
||||
public struct PrefabVariant
|
||||
{
|
||||
public DefectType DefectType;
|
||||
public GameObject Prefab;
|
||||
}
|
||||
|
||||
public List<PrefabVariant> DefectivePrefabVariants;
|
||||
|
||||
public void VisualizeDefect(DefectType defectType)
|
||||
{
|
||||
if (defectType == DefectType.None)
|
||||
{
|
||||
NormalPrefab.SetActive(true);
|
||||
|
||||
foreach (var variant in DefectivePrefabVariants)
|
||||
{
|
||||
variant.Prefab.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NormalPrefab.SetActive(false);
|
||||
|
||||
foreach (var variant in DefectivePrefabVariants)
|
||||
{
|
||||
variant.Prefab.SetActive(false);
|
||||
|
||||
if (defectType.HasFlag(variant.DefectType))
|
||||
{
|
||||
variant.Prefab.SetActive(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Products/DefectMeshSelector.cs.meta
Normal file
3
Assets/Scripts/Products/DefectMeshSelector.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 168e96bc0e2e4ddfa90949e485bcd0cd
|
||||
timeCreated: 1723979516
|
@@ -1,6 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DefectiveProduct : Product
|
||||
{
|
||||
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05b73befcbdd4bbfaaee667a8da86b1f
|
||||
timeCreated: 1723897738
|
4
Assets/Scripts/Products/IDefectVisualizer.cs
Normal file
4
Assets/Scripts/Products/IDefectVisualizer.cs
Normal file
@@ -0,0 +1,4 @@
|
||||
public interface IDefectVisualizer
|
||||
{
|
||||
public void VisualizeDefect(DefectType defectType);
|
||||
}
|
3
Assets/Scripts/Products/IDefectVisualizer.cs.meta
Normal file
3
Assets/Scripts/Products/IDefectVisualizer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ffa14c7e9444d31898f9446de6628ea
|
||||
timeCreated: 1723979215
|
@@ -2,5 +2,16 @@
|
||||
|
||||
public class Product : MonoBehaviour
|
||||
{
|
||||
public ProductType Type;
|
||||
public DefectType Defect;
|
||||
|
||||
public void ApplyDefect(DefectType defectType)
|
||||
{
|
||||
Defect = defectType;
|
||||
|
||||
foreach (var visualizer in GetComponents<IDefectVisualizer>())
|
||||
{
|
||||
visualizer.VisualizeDefect(defectType);
|
||||
}
|
||||
}
|
||||
}
|
@@ -2,8 +2,8 @@
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Product Description", menuName = "Data/Product Description", order = 0)]
|
||||
public class ProductDescription : ScriptableObject
|
||||
[CreateAssetMenu(fileName = "New Product Spawn Schedule", menuName = "Data/Product Spawn Schedule", order = 0)]
|
||||
public class ProductSpawnSchedule : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public struct Product
|
45
Assets/Scripts/Products/ProductType.cs
Normal file
45
Assets/Scripts/Products/ProductType.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Product Type", menuName = "Data/Product Type", order = 0)]
|
||||
public class ProductType : ScriptableObject
|
||||
{
|
||||
public Product Prefab;
|
||||
|
||||
[Serializable]
|
||||
public struct DefectProbability
|
||||
{
|
||||
public DefectType Defect;
|
||||
[Range(0,100)]
|
||||
public int Probability;
|
||||
}
|
||||
|
||||
public DefectProbability[] DefectProbabilities;
|
||||
|
||||
public static void SpawnProduct(ProductType type, Transform origin)
|
||||
{
|
||||
var newProduct = Instantiate(type.Prefab, origin);
|
||||
newProduct.Type = type;
|
||||
newProduct.ApplyDefect(type.SelectDefect());
|
||||
}
|
||||
|
||||
public DefectType SelectDefect()
|
||||
{
|
||||
float randomValue = Random.Range(0, 100);
|
||||
float sum = 0;
|
||||
|
||||
for (var i = 0; i < DefectProbabilities.Length; i++)
|
||||
{
|
||||
var defect = DefectProbabilities[i];
|
||||
|
||||
sum += defect.Probability;
|
||||
if (randomValue <= sum)
|
||||
{
|
||||
return defect.Defect;
|
||||
}
|
||||
}
|
||||
|
||||
return DefectType.None;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Products/ProductType.cs.meta
Normal file
3
Assets/Scripts/Products/ProductType.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcf4ec4eb272446d850eb3c9e72cd87f
|
||||
timeCreated: 1723979773
|
Reference in New Issue
Block a user