BlueGit

blue-star ggj-2020

Files

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

X9_T803.cs

New modules, fancy effects
timfa Tim Falken · pushed by timfa · 6 years ago
be3de6c4 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 ok = ((FlipSwitch)switchConnector.Connected).IsFlipped;
48 }
49 else
50 {
51 ok = false;
52 }
53 }
54 else
55 {
56 ok = false;
57 }
58
59 if (wireConnectorA.Connected != null)
60 {
61 if (wireConnectorA.Connected is WireHead)
62 {
63 if (((WireHead)wireConnectorA.Connected).MatchingWireHead != wireConnectorB.Connected)
64 {
65 ok = false;
66 }
67 }
68 else
69 {
70 ok = false;
71 }
72 }
73 else
74 {
75 ok = false;
76 }
77
78 buttonPressedCorrectly = ok;
79
80 if (ok)
81 ((LightComponent)lightConnector.Connected).TurnOn(Color.green);
82
83 if (!ok)
84 EjectComponents();
85 };
86 }
87 };
88
89 buttonConnector.OnDisconnect = c =>
90 {
91 if (c is Pushbutton)
92 {
93 Pushbutton btn = (Pushbutton)c;
94
95 btn.OnClick = null;
96 }
97 };
98 }
99}