Fixed level loading, added level reset

This commit is contained in:
Daniel Tyomin
2024-08-18 22:01:15 +02:00
parent 3036732a0d
commit 70d7cab3b9
13 changed files with 106 additions and 239 deletions

View File

@@ -1,13 +0,0 @@
using UnityEngine;
public class AudioAlarm : MonoBehaviour
{
public float Duration;
private bool _isPlaying;
public void PlayAlarm()
{
Debug.Log("Playing alarm");
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: c996d1be4ecb4e8d92bc4344f7f98854
timeCreated: 1723921340

View File

@@ -0,0 +1,4 @@
public interface IResetable
{
public void ResetMachine();
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6b152b88cf564370bd89748f325284b6
timeCreated: 1724010368

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class Converter: MonoBehaviour
public class Converter: MonoBehaviour, IResetable
{
public List<Product> inputProducts;
@@ -31,9 +31,16 @@ public class Converter: MonoBehaviour
}
public void Start()
{
ResetMachine();
}
public void ResetMachine()
{
_conversionTimer = conversionDuration;
CurrentHealth = MaxHealth;
inputProducts.Clear();
}
public void Update()

View File

@@ -3,12 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
public class ProductReceiver : MonoBehaviour
{
///HashSet<Rigidbody> enteredBodies = new HashSet<Rigidbody>();
public int normalProductCount;
public int defectiveProductCount;
{
private void OnTriggerEnter(Collider otherCollider)
{
var product = otherCollider.GetComponentInParent<Product>();

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
public class ProductSpawner : MonoBehaviour
public class ProductSpawner : MonoBehaviour, IResetable
{
public enum ProductionPhaseType
{
@@ -24,19 +24,34 @@ public class ProductSpawner : MonoBehaviour
}
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 (ProductionPhases.Count == 0)
if (RuntimeProductionPhases.Count == 0)
{
enabled = false;
return;
}
var currentPhase = ProductionPhases[0];
var currentPhase = RuntimeProductionPhases[0];
if (_remainingDuration <= 0)
{
@@ -54,7 +69,7 @@ public class ProductSpawner : MonoBehaviour
{
if (_remainingDuration <= 0)
{
ProductionPhases.RemoveAt(0);
RuntimeProductionPhases.RemoveAt(0);
}
return;
@@ -67,7 +82,7 @@ public class ProductSpawner : MonoBehaviour
if (_remainingDuration <= 0)
{
ProductionPhases.RemoveAt(0);
RuntimeProductionPhases.RemoveAt(0);
}
}
}

View File

@@ -3,12 +3,17 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class StationaryDefectDetector : MonoBehaviour
public class StationaryDefectDetector : MonoBehaviour, IResetable
{
public List<Product> _knownProducts;
public AudioClip goodSound;
public AudioClip badSound;
public void ResetMachine()
{
_knownProducts.Clear();
}
private void OnTriggerEnter(Collider other)
{