mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-08 23:03:43 +00:00
Messing with meshes and object spawning
This commit is contained in:
@@ -4,6 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class Converter: MonoBehaviour, IResetable
|
||||
{
|
||||
public ProductSpawner Spawner;
|
||||
public List<Product> inputProducts;
|
||||
|
||||
public ProductType expectedReagent;
|
||||
@@ -61,7 +62,7 @@ public class Converter: MonoBehaviour, IResetable
|
||||
|
||||
if (inputProducts[0].Type == expectedReagent)
|
||||
{
|
||||
ProductType.SpawnProduct(conversionProduct, outputPoint);
|
||||
Spawner.SpawnProduct(conversionProduct);
|
||||
inputProducts.RemoveAt(0);
|
||||
Destroy(currentProduct);
|
||||
}
|
||||
|
90
Assets/Scripts/Machines/ProductInput.cs
Normal file
90
Assets/Scripts/Machines/ProductInput.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProductInput : MonoBehaviour, IResetable
|
||||
{
|
||||
public enum ProductionPhaseType
|
||||
{
|
||||
Pause = 0,
|
||||
Production = 1,
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct ProductionPhase
|
||||
{
|
||||
public ProductionPhaseType Type;
|
||||
public ProductType ProductType;
|
||||
[Min(1f)]
|
||||
public float Duration;
|
||||
[Min(1f)]
|
||||
public float TotalSpawnCount;
|
||||
|
||||
public float SpawnInterval => Duration / TotalSpawnCount;
|
||||
}
|
||||
|
||||
public List<ProductionPhase> ProductionPhases;
|
||||
private List<ProductionPhase> RuntimeProductionPhases;
|
||||
|
||||
public ProductSpawner Spawner;
|
||||
|
||||
public float _remainingDuration;
|
||||
public float _spawnTimer;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ResetMachine();
|
||||
}
|
||||
|
||||
public void ResetMachine()
|
||||
{
|
||||
enabled = true;
|
||||
_remainingDuration = 0f;
|
||||
_spawnTimer = 0f;
|
||||
|
||||
RuntimeProductionPhases = new(ProductionPhases);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (RuntimeProductionPhases.Count == 0)
|
||||
{
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentPhase = RuntimeProductionPhases[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)
|
||||
{
|
||||
RuntimeProductionPhases.RemoveAt(0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_spawnTimer = currentPhase.SpawnInterval;
|
||||
|
||||
Spawner.SpawnProduct(currentPhase.ProductType);
|
||||
}
|
||||
|
||||
if (_remainingDuration <= 0)
|
||||
{
|
||||
RuntimeProductionPhases.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Machines/ProductInput.cs.meta
Normal file
3
Assets/Scripts/Machines/ProductInput.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13fa2421a3e649448c929ac42745ad65
|
||||
timeCreated: 1723896826
|
@@ -1,88 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ProductSpawner : MonoBehaviour, IResetable
|
||||
public class ProductSpawner: MonoBehaviour
|
||||
{
|
||||
public enum ProductionPhaseType
|
||||
{
|
||||
Pause = 0,
|
||||
Production = 1,
|
||||
}
|
||||
public List<Transform> PossibleOrientations;
|
||||
public Vector2 yRotation;
|
||||
|
||||
[Serializable]
|
||||
public struct ProductionPhase
|
||||
public void SpawnProduct(ProductType type)
|
||||
{
|
||||
public ProductionPhaseType Type;
|
||||
public ProductType ProductType;
|
||||
[Min(1f)]
|
||||
public float Duration;
|
||||
[Min(1f)]
|
||||
public float TotalSpawnCount;
|
||||
var randomIndex = Random.Range(0, PossibleOrientations.Count);
|
||||
var randomOrientation = PossibleOrientations[randomIndex];
|
||||
|
||||
public float SpawnInterval => Duration / TotalSpawnCount;
|
||||
var rotation = Quaternion.AngleAxis(Random.Range(yRotation.x, yRotation.y), Vector3.up) *
|
||||
randomOrientation.rotation;
|
||||
|
||||
ProductType.SpawnProduct(type, transform, randomOrientation.position, rotation);
|
||||
}
|
||||
|
||||
public List<ProductionPhase> ProductionPhases;
|
||||
private List<ProductionPhase> RuntimeProductionPhases;
|
||||
|
||||
public float _remainingDuration;
|
||||
public float _spawnTimer;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
ResetMachine();
|
||||
}
|
||||
|
||||
public void ResetMachine()
|
||||
{
|
||||
enabled = true;
|
||||
_remainingDuration = 0f;
|
||||
_spawnTimer = 0f;
|
||||
|
||||
RuntimeProductionPhases = new(ProductionPhases);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (RuntimeProductionPhases.Count == 0)
|
||||
{
|
||||
enabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var currentPhase = RuntimeProductionPhases[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)
|
||||
{
|
||||
RuntimeProductionPhases.RemoveAt(0);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_spawnTimer = currentPhase.SpawnInterval;
|
||||
|
||||
ProductType.SpawnProduct(currentPhase.ProductType, transform);
|
||||
}
|
||||
|
||||
if (_remainingDuration <= 0)
|
||||
{
|
||||
RuntimeProductionPhases.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13fa2421a3e649448c929ac42745ad65
|
||||
timeCreated: 1723896826
|
||||
fileFormatVersion: 2
|
||||
guid: d8b9c030eb764470a3082c1bae816ac0
|
||||
timeCreated: 1724011784
|
@@ -20,9 +20,9 @@ public class ProductType : ScriptableObject
|
||||
|
||||
public DefectProbability[] DefectProbabilities;
|
||||
|
||||
public static void SpawnProduct(ProductType type, Transform origin)
|
||||
public static void SpawnProduct(ProductType type, Transform parent, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
var newProduct = Instantiate(type.Prefab, origin);
|
||||
var newProduct = Instantiate(type.Prefab, position, rotation, parent);
|
||||
newProduct.Type = type;
|
||||
newProduct.ApplyDefect(type.SelectDefect());
|
||||
}
|
||||
|
Reference in New Issue
Block a user