| 1 | using System.Collections; |
| 2 | using System.Collections.Generic; |
| 3 | using UnityEngine; |
| 4 | |
| 5 | public class X9_T801 : ModuleBase |
| 6 | { |
| 7 | [SerializeField] private Connector lightConnector, 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 (wireConnectorA.Connected != null) |
| 44 | { |
| 45 | if (wireConnectorA.Connected is WireHead) |
| 46 | { |
| 47 | if(((WireHead)wireConnectorA.Connected).MatchingWireHead != wireConnectorB.Connected) |
| 48 | { |
| 49 | ok = false; |
| 50 | } |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | ok = false; |
| 55 | } |
| 56 | } |
| 57 | else |
| 58 | { |
| 59 | ok = false; |
| 60 | } |
| 61 | |
| 62 | buttonPressedCorrectly = ok; |
| 63 | |
| 64 | if (ok) |
| 65 | ((LightComponent)lightConnector.Connected).TurnOn(Color.green); |
| 66 | |
| 67 | if (!ok) |
| 68 | EjectComponents(); |
| 69 | }; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | buttonConnector.OnDisconnect = c => |
| 74 | { |
| 75 | if (c is Pushbutton) |
| 76 | { |
| 77 | Pushbutton btn = (Pushbutton)c; |
| 78 | |
| 79 | btn.OnClick = null; |
| 80 | } |
| 81 | }; |
| 82 | } |
| 83 | } |