BlueGit

blue-star ggj-2020

Files

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

X9_T803.cs

f93b9f9e History
X9_T803.cs 2.8 KiB Download Raw
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class X9_T803 : ModuleBase
6{
7 [SerializeField] private Connector lightConnector, switchConnector, buttonConnector, wireConnectorA, wireConnectorB;
8 private bool buttonPressedCorrectly;
9
10 protected override bool TestCorrectness()
11 {
12 return buttonPressedCorrectly;
13 }
14
15 void Start()
16 {
17 buttonConnector.OnConnect = c =>
18 {
19 if (c is Pushbutton)
20 {
21 Pushbutton btn = (Pushbutton)c;
22
23 btn.OnClick = () =>
24 {
25 bool ok = true;
26
27 if (lightConnector.Connected != null)
28 {
29 if (lightConnector.Connected is LightComponent)
30 {
31 //ok
32 }
33 else
34 {
35 ok = false;
36 }
37 }
38 else
39 {
40 ok = false;
41 }
42
43 if (switchConnector.Connected != null)
44 {
45 if (switchConnector.Connected is FlipSwitch)
46 {
47 if(ok)
48 ok = ((FlipSwitch)switchConnector.Connected).IsFlipped;
49 }
50 else
51 {
52 ok = false;
53 }
54 }
55 else
56 {
57 ok = false;
58 }
59
60 if (wireConnectorA.Connected != null)
61 {
62 if (wireConnectorA.Connected is WireHead)
63 {
64 if (((WireHead)wireConnectorA.Connected).MatchingWireHead != wireConnectorB.Connected)
65 {
66 ok = false;
67 }
68 }
69 else
70 {
71 ok = false;
72 }
73 }
74 else
75 {
76 ok = false;
77 }
78
79 buttonPressedCorrectly = ok;
80
81 if (ok)
82 ((LightComponent)lightConnector.Connected).TurnOn(Color.green);
83
84 if (!ok)
85 EjectComponents();
86 };
87 }
88 };
89
90 buttonConnector.OnDisconnect = c =>
91 {
92 if (c is Pushbutton)
93 {
94 Pushbutton btn = (Pushbutton)c;
95
96 btn.OnClick = null;
97 }
98 };
99 }
100}