mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-09 07:13:42 +00:00
Added more prefabs
This commit is contained in:
34
Assets/Scripts/Machines/ProductReceiver.cs
Normal file
34
Assets/Scripts/Machines/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/Machines/ProductReceiver.cs.meta
Normal file
3
Assets/Scripts/Machines/ProductReceiver.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6de8f4eed85043df853aee4396834741
|
||||
timeCreated: 1723897952
|
73
Assets/Scripts/Machines/ProductSpawner.cs
Normal file
73
Assets/Scripts/Machines/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/Machines/ProductSpawner.cs.meta
Normal file
3
Assets/Scripts/Machines/ProductSpawner.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13fa2421a3e649448c929ac42745ad65
|
||||
timeCreated: 1723896826
|
92
Assets/Scripts/Machines/TrashBin.cs
Normal file
92
Assets/Scripts/Machines/TrashBin.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TrashBin : MonoBehaviour
|
||||
{
|
||||
public float CooldownDuration;
|
||||
private float _cooldownTimer;
|
||||
|
||||
private float _incinerationTimer = 1f;
|
||||
public float IncinerationDuration = 1f;
|
||||
|
||||
public float doorVelocity = 5f;
|
||||
public Transform DoorTransform;
|
||||
public Transform OpenAnchor;
|
||||
public Transform ClosedAnchor;
|
||||
private Vector3 _targetPosition;
|
||||
|
||||
List<Product> enteredProducts = new List<Product>();
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_targetPosition = OpenAnchor.position;
|
||||
}
|
||||
|
||||
public void OnTriggerEnter(Collider otherCollider)
|
||||
{
|
||||
var rb = otherCollider.GetComponent<Rigidbody>();
|
||||
|
||||
if (!rb)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (otherCollider.TryGetComponent(out Product product))
|
||||
{
|
||||
if (!enteredProducts.Contains(product))
|
||||
{
|
||||
enteredProducts.Add(product);
|
||||
}
|
||||
|
||||
_cooldownTimer = CooldownDuration;
|
||||
_targetPosition = ClosedAnchor.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
rb.AddForce(5f * Vector3.up);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnTriggerExit(Collider collider)
|
||||
{
|
||||
if (collider.TryGetComponent(out Product product))
|
||||
{
|
||||
if (enteredProducts.Contains(product))
|
||||
{
|
||||
enteredProducts.Remove(product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
DoorTransform.position = Vector3.Lerp(
|
||||
DoorTransform.position,
|
||||
_targetPosition,
|
||||
Time.deltaTime * doorVelocity);
|
||||
|
||||
if (_cooldownTimer <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_cooldownTimer -= Time.deltaTime;
|
||||
_incinerationTimer -= Time.deltaTime;
|
||||
|
||||
if (_incinerationTimer <= 0)
|
||||
{
|
||||
foreach (var product in enteredProducts)
|
||||
{
|
||||
Destroy(product.gameObject);
|
||||
}
|
||||
|
||||
enteredProducts.Clear();
|
||||
_incinerationTimer = IncinerationDuration;
|
||||
}
|
||||
|
||||
if (_cooldownTimer <= 0)
|
||||
{
|
||||
_targetPosition = OpenAnchor.position;
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/Scripts/Machines/TrashBin.cs.meta
Normal file
3
Assets/Scripts/Machines/TrashBin.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46eefd3f602b47379d40397411611b9b
|
||||
timeCreated: 1723917379
|
Reference in New Issue
Block a user