-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuger.cs
108 lines (100 loc) · 2.91 KB
/
Auger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using UnityEngine;
public class Auger : Machine
{
public float amount;
public int speed = 1;
public int power;
public bool hasHeatExchanger;
public int heat;
public int cooling;
public GameObject outputObject;
public GameObject powerObject;
public ConduitItem conduitItem;
public PowerReceiver powerReceiver;
public Material lineMat;
public string ID = "unassigned";
public string creationMethod;
public bool powerON;
private LineRenderer connectionLine;
private StateManager stateManager;
private int machineTimer;
private int warmup;
//! Called by unity engine on start up to initialize variables.
public void Start()
{
powerReceiver = gameObject.AddComponent<PowerReceiver>();
connectionLine = gameObject.AddComponent<LineRenderer>();
conduitItem = GetComponentInChildren<ConduitItem>(true);
stateManager = FindObjectOfType<StateManager>();
connectionLine.startWidth = 0.2f;
connectionLine.endWidth = 0.2f;
connectionLine.material = lineMat;
connectionLine.loop = true;
connectionLine.enabled = false;
}
//! Called by MachineManager update coroutine.
public override void UpdateMachine()
{
if (ID == "unassigned" || stateManager.initMachines == false)
return;
GetComponent<PhysicsHandler>().UpdatePhysics();
UpdatePowerReceiver();
if (warmup < 10)
{
warmup++;
}
else if (speed > power)
{
speed = power > 0 ? power : 1;
}
if (speed > 1)
{
heat = speed - 1 - cooling;
}
else
{
heat = 0;
}
if (heat < 0)
{
heat = 0;
}
if (outputObject != null)
{
connectionLine.SetPosition(0, transform.position);
connectionLine.SetPosition(1, outputObject.transform.position);
connectionLine.enabled = true;
}
else
{
connectionLine.enabled = false;
}
if (powerON == true && speed > 0)
{
conduitItem.active = true;
GetComponent<Light>().enabled = true;
GetComponent<AudioSource>().enabled = true;
machineTimer += 1;
if (machineTimer > 5)
{
amount += speed - heat;
machineTimer = 0;
}
}
else
{
machineTimer = 0;
conduitItem.active = false;
GetComponent<Light>().enabled = false;
GetComponent<AudioSource>().enabled = false;
}
}
//! Gets power values from power receiver.
private void UpdatePowerReceiver()
{
powerReceiver.ID = ID;
power = powerReceiver.power;
powerON = powerReceiver.powerON;
powerObject = powerReceiver.powerObject;
}
}