mirror of
https://github.com/nothke/quality-control.git
synced 2025-08-09 07:13:42 +00:00
Fixed level loading, added level reset
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class Scoreboard: MonoBehaviour
|
||||
@@ -14,18 +15,41 @@ public class Scoreboard: MonoBehaviour
|
||||
public bool _running;
|
||||
|
||||
public TextMeshPro textMesh;
|
||||
|
||||
public void Start()
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (!Instance)
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
SetObjective(CurrentObjective);
|
||||
UpdateText();
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[MenuItem("Tools/Restart Level")]
|
||||
#endif
|
||||
public static void RestartLevel()
|
||||
{
|
||||
foreach (var machine in StagingManager.Instance.GetComponentsInChildren<IResetable>(true))
|
||||
{
|
||||
machine.ResetMachine();
|
||||
}
|
||||
|
||||
var allProducts = FindObjectsOfType<Product>();
|
||||
for (int i = 0; i < allProducts.Length; i++)
|
||||
{
|
||||
Destroy(allProducts[i].gameObject);
|
||||
}
|
||||
|
||||
Instance.SetObjective(Instance.CurrentObjective);
|
||||
Instance.UpdateText();
|
||||
}
|
||||
|
||||
public void SetObjective(LevelObjective objective)
|
||||
{
|
||||
CurrentObjective = objective;
|
||||
|
@@ -3,15 +3,4 @@
|
||||
public class StageProp: MonoBehaviour
|
||||
{
|
||||
public StagingManager.StageEnum ActiveAtStages;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
StagingManager.RegisterStageProp(this);
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
StagingManager.RemoveStageProp(this);
|
||||
}
|
||||
}
|
@@ -6,7 +6,6 @@ using UnityEngine;
|
||||
public class StagingManager: MonoBehaviour
|
||||
{
|
||||
public static StagingManager Instance;
|
||||
public static List<StageProp> StageProps;
|
||||
|
||||
public List<LevelObjective> Objectives;
|
||||
|
||||
@@ -15,8 +14,9 @@ public class StagingManager: MonoBehaviour
|
||||
[Flags]
|
||||
public enum StageEnum
|
||||
{
|
||||
Level1 = 1,
|
||||
Level2 = 2,
|
||||
Level1 = 1 << 0,
|
||||
Level2 = 1 << 1,
|
||||
Level3 = 1 << 2,
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
@@ -26,40 +26,15 @@ public class StagingManager: MonoBehaviour
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
StageProps.Clear();
|
||||
}
|
||||
|
||||
public static void RegisterStageProp(StageProp stageProp)
|
||||
{
|
||||
if (StageProps == null)
|
||||
{
|
||||
StageProps = new List<StageProp>();
|
||||
}
|
||||
|
||||
if (!StageProps.Contains(stageProp))
|
||||
{
|
||||
StageProps.Add(stageProp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveStageProp(StageProp stageProp)
|
||||
{
|
||||
if (StageProps.Contains(stageProp))
|
||||
{
|
||||
StageProps.Remove(stageProp);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetStage(StageEnum stage)
|
||||
{
|
||||
Instance.CurrentStage = stage;
|
||||
|
||||
foreach (var stageProp in StageProps)
|
||||
foreach (var stageProp in FindObjectsOfType<StageProp>(true))
|
||||
{
|
||||
stageProp.gameObject.SetActive((stageProp.ActiveAtStages & stage) != 0);
|
||||
Debug.Log(stageProp.ActiveAtStages.HasFlag(stage));
|
||||
stageProp.gameObject.SetActive(stageProp.ActiveAtStages.HasFlag(stage));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user