mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Prototyped the object production scheduling.
This commit is contained in:
@@ -23,6 +23,8 @@ public class StagingManager: MonoBehaviour
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
SetStage(StageEnum.Level1);
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
|
34
Assets/Scripts/ProductReceiver.cs
Normal file
34
Assets/Scripts/ProductReceiver.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProductReceiver : MonoBehaviour
|
||||
{
|
||||
///HashSet<Rigidbody> enteredBodies = new HashSet<Rigidbody>();
|
||||
|
||||
public int normalProductCount;
|
||||
public int defectiveProductCount;
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
var rb = collision.rigidbody;
|
||||
|
||||
if (!rb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//enteredBodies.Add(rb);
|
||||
|
||||
if (rb.GetComponent<DefectiveProduct>())
|
||||
{
|
||||
defectiveProductCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
normalProductCount++;
|
||||
}
|
||||
|
||||
Destroy(rb.gameObject);
|
||||
}
|
||||
}
|
3
Assets/Scripts/ProductReceiver.cs.meta
Normal file
3
Assets/Scripts/ProductReceiver.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6de8f4eed85043df853aee4396834741
|
||||
timeCreated: 1723897952
|
3
Assets/Scripts/Products.meta
Normal file
3
Assets/Scripts/Products.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9adc44b5a83c4f599556f32f639d3934
|
||||
timeCreated: 1723896059
|
6
Assets/Scripts/Products/DefectiveProduct.cs
Normal file
6
Assets/Scripts/Products/DefectiveProduct.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DefectiveProduct : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
3
Assets/Scripts/Products/DefectiveProduct.cs.meta
Normal file
3
Assets/Scripts/Products/DefectiveProduct.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 05b73befcbdd4bbfaaee667a8da86b1f
|
||||
timeCreated: 1723897738
|
36
Assets/Scripts/Products/ProductDescription.cs
Normal file
36
Assets/Scripts/Products/ProductDescription.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
[CreateAssetMenu(fileName = "New Product Description", menuName = "Data/Product Description", order = 0)]
|
||||
public class ProductDescription : ScriptableObject
|
||||
{
|
||||
[Serializable]
|
||||
public struct Product
|
||||
{
|
||||
public GameObject Prefab;
|
||||
[Range(0,100)]
|
||||
public int Probability;
|
||||
}
|
||||
|
||||
public Product[] Products;
|
||||
|
||||
public GameObject GetRandomProduct()
|
||||
{
|
||||
float randomValue = Random.value;
|
||||
float sum = 0;
|
||||
|
||||
for (var i = 0; i < Products.Length; i++)
|
||||
{
|
||||
var product = Products[i];
|
||||
|
||||
sum += product.Probability / 100f;
|
||||
if (randomValue <= sum)
|
||||
{
|
||||
return product.Prefab;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
3
Assets/Scripts/Products/ProductDescription.cs.meta
Normal file
3
Assets/Scripts/Products/ProductDescription.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a80c2e8703664de8943062f03eedfe17
|
||||
timeCreated: 1723896074
|
73
Assets/Scripts/Products/ProductSpawner.cs
Normal file
73
Assets/Scripts/Products/ProductSpawner.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProductSpawner : MonoBehaviour
|
||||
{
|
||||
public enum ProductionPhaseType
|
||||
{
|
||||
Pause = 0,
|
||||
Production = 1,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct ProductionPhase
|
||||
{
|
||||
public ProductionPhaseType Type;
|
||||
public ProductDescription Description;
|
||||
[Min(1f)]
|
||||
public float Duration;
|
||||
[Min(1f)]
|
||||
public float TotalSpawnCount;
|
||||
|
||||
public float SpawnInterval => Duration / TotalSpawnCount;
|
||||
}
|
||||
|
||||
public List<ProductionPhase> ProductionPhases;
|
||||
|
||||
public float _remainingDuration;
|
||||
public float _spawnTimer;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (ProductionPhases.Count == 0)
|
||||
{
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentPhase = ProductionPhases[0];
|
||||
|
||||
if (_remainingDuration <= 0)
|
||||
{
|
||||
_remainingDuration = currentPhase.Duration;
|
||||
_spawnTimer = 0f;
|
||||
}
|
||||
|
||||
_remainingDuration -= Time.deltaTime;
|
||||
|
||||
if (currentPhase.Type != ProductionPhaseType.Pause)
|
||||
{
|
||||
_spawnTimer -= Time.deltaTime;
|
||||
|
||||
if (_spawnTimer >= 0f)
|
||||
{
|
||||
if (_remainingDuration <= 0)
|
||||
{
|
||||
ProductionPhases.RemoveAt(0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_spawnTimer = currentPhase.SpawnInterval;
|
||||
|
||||
Instantiate(currentPhase.Description.GetRandomProduct(), transform.position, Quaternion.identity);
|
||||
}
|
||||
|
||||
if (_remainingDuration <= 0)
|
||||
{
|
||||
ProductionPhases.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Products/ProductSpawner.cs.meta
Normal file
3
Assets/Scripts/Products/ProductSpawner.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13fa2421a3e649448c929ac42745ad65
|
||||
timeCreated: 1723896826
|
Reference in New Issue
Block a user