mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-09 23:23:44 +00:00
Reworking item spawn, adding item conversion.
This commit is contained in:
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