BlueGit

blue-star ggj-2020

Files

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

SENSE_B.cs

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