public void StopListeningToTrainInputEvents() { if (!loco || !loco.IsLoco) { return; } if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening throttle change on base loco controller"); } baseController.ThrottleUpdated -= OnTrainThrottleChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening brake change on base loco controller"); } baseController.BrakeUpdated -= OnTrainBrakeChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening indepBrake change on base loco controller"); } baseController.IndependentBrakeUpdated -= OnTrainIndependentBrakeChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening reverser change on base loco controller"); } baseController.ReverserUpdated -= OnTrainReverserStateChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening sander change on base loco controller"); } baseController.SandersUpdated -= OnTrainSanderChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Stop listening to train specific events"); } switch (loco.carType) { case TrainCarType.LocoShunter: FuseBoxPowerController fuseBox = loco.interior.GetComponentInChildren <ShunterDashboardControls>().fuseBoxPowerController; for (int i = 0; i < fuseBox.sideFusesObj.Length; i++) { ToggleSwitchBase sideFuse = fuseBox.sideFusesObj[i].GetComponent <ToggleSwitchBase>(); switch (i) { case 0: sideFuse.ValueChanged -= OnTrainSideFuse_1Changed; break; case 1: sideFuse.ValueChanged -= OnTrainSideFuse_2Changed; break; } } fuseBox.mainFuseObj.GetComponent <ToggleSwitchBase>().ValueChanged -= OnTrainMainFuseChanged; fuseBox.powerRotaryObj.GetComponent <RotaryAmplitudeChecker>().RotaryStateChanged -= OnTrainFusePowerStarterStateChanged; break; } }
public void ListenToTrainInputEvents() { if (!loco.IsLoco && isAlreadyListening) { return; } if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen to base loco controller"); } baseController = loco.GetComponent <LocoControllerBase>(); if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen throttle change on base loco controller"); } baseController.ThrottleUpdated += OnTrainThrottleChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen brake change on base loco controller"); } baseController.BrakeUpdated += OnTrainBrakeChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen indepBrake change on base loco controller"); } baseController.IndependentBrakeUpdated += OnTrainIndependentBrakeChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen reverser change on base loco controller"); } baseController.ReverserUpdated += OnTrainReverserStateChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen sander change on base loco controller"); } baseController.SandersUpdated += OnTrainSanderChanged; if (loco.logicCar != null) { Main.Log($"[{loco.ID}] Listen to specific train events"); } switch (loco.carType) { case TrainCarType.LocoShunter: ShunterDashboardControls shunterDashboard = loco.interior.GetComponentInChildren <ShunterDashboardControls>(); FuseBoxPowerController fuseBox = shunterDashboard.fuseBoxPowerController; for (int i = 0; i < fuseBox.sideFusesObj.Length; i++) { ToggleSwitchBase sideFuse = fuseBox.sideFusesObj[i].GetComponent <ToggleSwitchBase>(); switch (i) { case 0: sideFuse.ValueChanged += OnTrainSideFuse_1Changed; break; case 1: sideFuse.ValueChanged += OnTrainSideFuse_2Changed; break; } } fuseBox.mainFuseObj.GetComponent <ToggleSwitchBase>().ValueChanged += OnTrainMainFuseChanged; shunterDashboard.hornObj.GetComponent <ControlImplBase>().ValueChanged += ShunterHornUsed; SingletonBehaviour <CoroutineManager> .Instance.Run(RotaryAmplitudeCheckerStartListen(fuseBox)); break; } isAlreadyListening = true; }