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