using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class SENSE_A : ModuleBase { [SerializeField] private Connector leftBulb, midBulb, rightBulb, leftButton, midbutton, rightButton; private LightComponent lB = null; private LightComponent mB = null; private LightComponent rB = null; private bool canPush { get { return mB != null && rB != null && lB != null; } } protected override bool TestCorrectness() { if (leftBulb.Connected == null || !(leftBulb.Connected is LightComponent) || !((LightComponent)leftBulb.Connected).LightOn) return false; if (midBulb.Connected == null || !(midBulb.Connected is LightComponent) || !((LightComponent)midBulb.Connected).LightOn) return false; if (rightBulb.Connected == null || !(rightBulb.Connected is LightComponent) || !((LightComponent)rightBulb.Connected).LightOn) return false; return true; } // Start is called before the first frame update void Start() { mB = null; rB = null; lB = null; if (leftBulb.Connected != null && leftBulb.Connected is LightComponent) lB = (LightComponent)leftBulb.Connected; if (midBulb.Connected != null && midBulb.Connected is LightComponent) mB = (LightComponent)midBulb.Connected; if (rightBulb.Connected != null && rightBulb.Connected is LightComponent) rB = (LightComponent)rightBulb.Connected; leftBulb.OnConnect = c => { if (c is LightComponent) { if (UnityEngine.Random.value > 0.6f) { ((LightComponent)c).TurnOn(Color.yellow); } } else EjectComponents(); }; midBulb.OnConnect = c => { if (c is LightComponent) { if (UnityEngine.Random.value > 0.6f) { ((LightComponent)c).TurnOn(Color.yellow); } } else EjectComponents(); }; rightBulb.OnConnect = c => { if (c is LightComponent) { if (UnityEngine.Random.value > 0.6f) { ((LightComponent)c).TurnOn(Color.yellow); } } else EjectComponents(); }; leftBulb.OnDisconnect = c => { EjectComponents(); }; midBulb.OnDisconnect = c => { EjectComponents(); }; rightBulb.OnDisconnect = c => { EjectComponents(); }; leftButton.OnConnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = () => { if(canPush) { ToggleLight(lB); ToggleLight(mB); } else EjectComponents(); }; } else EjectComponents(); }; leftButton.OnDisconnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = null; } }; // midbutton.OnConnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = () => { if (canPush) { ToggleLight(rB); ToggleLight(mB); ToggleLight(lB); } else EjectComponents(); }; } else EjectComponents(); }; midbutton.OnDisconnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = null; } }; // rightButton.OnConnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = () => { if (canPush) { ToggleLight(rB); ToggleLight(mB); } else EjectComponents(); }; } else EjectComponents(); }; rightButton.OnDisconnect = c => { if (c is Pushbutton) { Pushbutton btn = (Pushbutton)c; btn.OnClick = null; } }; } private void ToggleLight(LightComponent light) { if (light.LightOn) light.TurnOff(); else light.TurnOn(Color.yellow); } }