BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / GAME / Scripts / Modules / SENSE_A.cs

SENSE_A.cs

New modules, fancy effects
timfa Tim Falken · pushed by timfa · 6 years ago
be3de6c4 History
SENSE_A.cs 4.0 KiB Download Raw
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using UnityEngine;
5
6public class SENSE_A : ModuleBase
7{
8 [SerializeField] private Connector leftBulb, midBulb, rightBulb, leftButton, midbutton, rightButton;
9
10 protected override bool TestCorrectness()
11 {
12 if (leftBulb.Connected == null || !(leftBulb.Connected is LightComponent) || !((LightComponent)leftBulb.Connected).LightOn)
13 return false;
14
15 if (midBulb.Connected == null || !(midBulb.Connected is LightComponent) || !((LightComponent)midBulb.Connected).LightOn)
16 return false;
17
18 if (rightBulb.Connected == null || !(rightBulb.Connected is LightComponent) || !((LightComponent)rightBulb.Connected).LightOn)
19 return false;
20
21 return true;
22 }
23
24 // Start is called before the first frame update
25 void Start()
26 {
27 LightComponent lB = null;
28 LightComponent mB = null;
29 LightComponent rB = null;
30
31 if (leftBulb.Connected != null && leftBulb.Connected is LightComponent)
32 lB = (LightComponent)leftBulb.Connected;
33
34 if (midBulb.Connected != null && midBulb.Connected is LightComponent)
35 mB = (LightComponent)midBulb.Connected;
36
37 if (rightBulb.Connected != null && rightBulb.Connected is LightComponent)
38 rB = (LightComponent)rightBulb.Connected;
39
40 bool canPush = mB != null && rB != null && lB != null;
41
42 leftBulb.OnDisconnect = c =>
43 {
44 EjectComponents();
45 };
46
47 midBulb.OnDisconnect = c =>
48 {
49 EjectComponents();
50 };
51
52 rightBulb.OnDisconnect = c =>
53 {
54 EjectComponents();
55 };
56
57 leftButton.OnConnect = c =>
58 {
59 if (c is Pushbutton)
60 {
61 Pushbutton btn = (Pushbutton)c;
62
63 btn.OnClick = () =>
64 {
65 if(canPush)
66 {
67 ToggleLight(lB);
68 ToggleLight(mB);
69 }
70 else
71 EjectComponents();
72 };
73 }
74 else
75 EjectComponents();
76 };
77
78 leftButton.OnDisconnect = c =>
79 {
80 if (c is Pushbutton)
81 {
82 Pushbutton btn = (Pushbutton)c;
83
84 btn.OnClick = null;
85 }
86 };
87 //
88 midbutton.OnConnect = c =>
89 {
90 if (c is Pushbutton)
91 {
92 Pushbutton btn = (Pushbutton)c;
93
94 btn.OnClick = () =>
95 {
96 if (canPush)
97 {
98 ToggleLight(rB);
99 ToggleLight(mB);
100 ToggleLight(lB);
101 }
102 else
103 EjectComponents();
104 };
105 }
106 else
107 EjectComponents();
108 };
109
110 midbutton.OnDisconnect = c =>
111 {
112 if (c is Pushbutton)
113 {
114 Pushbutton btn = (Pushbutton)c;
115
116 btn.OnClick = null;
117 }
118 };
119 //
120 rightButton.OnConnect = c =>
121 {
122 if (c is Pushbutton)
123 {
124 Pushbutton btn = (Pushbutton)c;
125
126 btn.OnClick = () =>
127 {
128 if (canPush)
129 {
130 ToggleLight(rB);
131 ToggleLight(mB);
132 }
133 else
134 EjectComponents();
135 };
136 }
137 else
138 EjectComponents();
139 };
140
141 rightButton.OnDisconnect = c =>
142 {
143 if (c is Pushbutton)
144 {
145 Pushbutton btn = (Pushbutton)c;
146
147 btn.OnClick = null;
148 }
149 };
150 }
151
152 private void ToggleLight(LightComponent light)
153 {
154 if (light.LightOn)
155 light.TurnOff();
156 else
157 light.TurnOn(Color.yellow);
158 }
159}