Implementing block manager class.

This commit is contained in:
Droog71 2021-05-17 12:24:26 -05:00
parent 9f1628c3aa
commit 04d1d306a2
9 changed files with 59 additions and 92 deletions

View File

@ -1,8 +1,7 @@
using UnityEngine;
public class AirLock : MonoBehaviour
public class AirLock : Machine
{
private float updateTick;
private StateManager stateManager;
public string ID = "unassigned";
public int address;
@ -22,20 +21,9 @@ public class AirLock : MonoBehaviour
}
//! Called once per frame by unity engine.
public void Update()
public override void UpdateMachine()
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
//! Toggle the open or closed state of the hatchway.

9
Block.cs Normal file
View File

@ -0,0 +1,9 @@
using UnityEngine;
public class Block : MonoBehaviour
{
public virtual void UpdateBlock()
{
}
}

29
BlockManager.cs Normal file
View File

@ -0,0 +1,29 @@
using System.Collections;
using UnityEngine;
public class BlockManager : MonoBehaviour
{
private bool busy;
private Coroutine blockUpdateCoroutine;
//! Called once per frame by unity engine.
public void Update()
{
if (busy == false && GetComponent<StateManager>().worldLoaded == true)
{
blockUpdateCoroutine = StartCoroutine(BlockUpdateCoroutine());
}
}
private IEnumerator BlockUpdateCoroutine()
{
busy = true;
Block[] blocks = FindObjectsOfType<Block>();
foreach (Block block in blocks)
{
block.UpdateBlock();
yield return null;
}
busy = false;
}
}

View File

@ -6,7 +6,6 @@ public class Brick : MonoBehaviour
public string ID = "unassigned";
public string creationMethod;
public int address;
private float updateTick;
private StateManager stateManager;
//! Called by unity engine on start up to initialize variables.
@ -18,20 +17,9 @@ public class Brick : MonoBehaviour
//! Called once per frame by unity engine.
public void Update()
{
if (ID == "unassigned")
if (ID == "unassigned" || stateManager.Busy())
return;
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}

View File

@ -1,12 +1,11 @@
using UnityEngine;
//! This class is attached to all glass block prefabs.
public class Glass : MonoBehaviour
public class Glass : Block
{
public string ID = "unassigned";
public string creationMethod;
public int address;
private float updateTick;
private StateManager stateManager;
//! Called by unity engine on start up to initialize variables.
@ -16,22 +15,11 @@ public class Glass : MonoBehaviour
}
//! Called once per frame by unity engine.
public void Update()
public override void UpdateBlock()
{
if (ID == "unassigned")
if (ID == "unassigned" || stateManager.Busy())
return;
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}

View File

@ -1,12 +1,11 @@
using UnityEngine;
//! This class is attached to all iron block prefabs.
public class IronBlock : MonoBehaviour
public class IronBlock : Block
{
public string ID = "unassigned";
public string creationMethod;
public int address;
private float updateTick;
private StateManager stateManager;
//! Called by unity engine on start up to initialize variables.
@ -16,22 +15,11 @@ public class IronBlock : MonoBehaviour
}
//! Called once per frame by unity engine.
public void Update()
public override void UpdateBlock()
{
if (ID == "unassigned")
if (ID == "unassigned" || stateManager.Busy())
return;
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}

View File

@ -26,5 +26,4 @@ public class MachineManager : MonoBehaviour
}
busy = false;
}
}
}

View File

@ -1,6 +1,6 @@
using UnityEngine;
public class ModBlock : MonoBehaviour
public class ModBlock : Block
{
private Material material;
private StateManager stateManager;
@ -8,7 +8,6 @@ public class ModBlock : MonoBehaviour
private GameManager gameManager;
public GameObject glassBreak;
private bool init;
private float updateTick;
public int address;
public string ID = "unassigned";
public string blockName;
@ -23,7 +22,7 @@ public class ModBlock : MonoBehaviour
}
//! Called once per frame by unity engine.
public void Update()
public override void UpdateBlock()
{
if (!stateManager.Busy() && init == false)
{
@ -42,16 +41,7 @@ public class ModBlock : MonoBehaviour
if (ID != "unassigned")
{
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}
}

View File

@ -1,13 +1,12 @@
using UnityEngine;
//! This class is attached to all steel block prefabs.
public class Steel : MonoBehaviour
public class Steel : Block
{
public string ID = "unassigned";
private StateManager stateManager;
public string creationMethod;
public int address;
private float updateTick;
//! Called by unity engine on start up to initialize variables.
public void Start()
@ -16,22 +15,11 @@ public class Steel : MonoBehaviour
}
//! Called once per frame by unity engine.
public void Update()
public override void UpdateBlock()
{
if (ID == "unassigned")
if (ID == "unassigned" || stateManager.Busy())
return;
updateTick += 1 * Time.deltaTime;
if (updateTick > 0.5f + (address * 0.001f))
{
if (stateManager.Busy())
{
updateTick = 0;
return;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
updateTick = 0;
}
GetComponent<PhysicsHandler>().UpdatePhysics();
}
}