Implementing block manager class.
This commit is contained in:
parent
9f1628c3aa
commit
04d1d306a2
18
AirLock.cs
18
AirLock.cs
@ -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
9
Block.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Block : MonoBehaviour
|
||||
{
|
||||
public virtual void UpdateBlock()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
29
BlockManager.cs
Normal file
29
BlockManager.cs
Normal 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;
|
||||
}
|
||||
}
|
16
Brick.cs
16
Brick.cs
@ -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();
|
||||
}
|
||||
}
|
||||
|
20
Glass.cs
20
Glass.cs
@ -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();
|
||||
}
|
||||
}
|
||||
|
20
IronBlock.cs
20
IronBlock.cs
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -26,5 +26,4 @@ public class MachineManager : MonoBehaviour
|
||||
}
|
||||
busy = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
16
ModBlock.cs
16
ModBlock.cs
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
20
Steel.cs
20
Steel.cs
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user