| 1 | using System; |
| 2 | using System.Collections; |
| 3 | using System.Collections.Generic; |
| 4 | using UnityEngine; |
| 5 | |
| 6 | public class X9_T802 : ModuleBase |
| 7 | { |
| 8 | [SerializeField] private Connector switchConnector, buttonConnector, wireConnectorA, wireConnectorB; |
| 9 | private bool buttonPressedCorrectly; |
| 10 | |
| 11 | protected override bool TestCorrectness() |
| 12 | { |
| 13 | return buttonPressedCorrectly; |
| 14 | } |
| 15 | |
| 16 | void Start() |
| 17 | { |
| 18 | buttonConnector.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 (switchConnector.Connected != null) |
| 29 | { |
| 30 | if (switchConnector.Connected is FlipSwitch) |
| 31 | { |
| 32 | ok = ((FlipSwitch)switchConnector.Connected).IsFlipped; |
| 33 | } |
| 34 | else |
| 35 | { |
| 36 | ok = false; |
| 37 | } |
| 38 | } |
| 39 | else |
| 40 | { |
| 41 | ok = false; |
| 42 | } |
| 43 | |
| 44 | if (wireConnectorA.Connected != null) |
| 45 | { |
| 46 | if (wireConnectorA.Connected is WireHead) |
| 47 | { |
| 48 | if (((WireHead)wireConnectorA.Connected).MatchingWireHead != wireConnectorB.Connected) |
| 49 | { |
| 50 | ok = false; |
| 51 | } |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | ok = false; |
| 56 | } |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | ok = false; |
| 61 | } |
| 62 | |
| 63 | buttonPressedCorrectly = ok; |
| 64 | |
| 65 | if (!ok) |
| 66 | EjectComponents(); |
| 67 | }; |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | buttonConnector.OnDisconnect = c => |
| 72 | { |
| 73 | if (c is Pushbutton) |
| 74 | { |
| 75 | Pushbutton btn = (Pushbutton)c; |
| 76 | |
| 77 | btn.OnClick = null; |
| 78 | } |
| 79 | }; |
| 80 | } |
| 81 | } |