static void Prefix(LocoControllerDiesel __instance, ToggleDirection toggle) { TrainCar targetCar = __instance.GetComponent <TrainCar>(); Trainset trainset = targetCar.trainset; if (trainset == null) { return; } for (int i = 0; i < trainset.cars.Count; i++) { TrainCar car = trainset.cars[i]; if (targetCar.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController != null) { locoController.SetSandersOn(toggle == ToggleDirection.UP); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController != null) { locoController.SetSandersOn(toggle == ToggleDirection.UP); } } } }
static IEnumerator <object> AttachListeners() { yield return((object)null); DV.CabControls.ControlImplBase sandDeployCtrl = instance.sandDeployBtn.GetComponent <DV.CabControls.ControlImplBase>(); sandDeployCtrl.ValueChanged += (e => { if (PlayerManager.Car == null || PlayerManager.Car.trainset == null) { return; } for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++) { TrainCar car = PlayerManager.Car.trainset.cars[i]; if (PlayerManager.Car.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController) { locoController.SetSandersOn(e.newValue >= 0.5f); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetSandersOn(e.newValue >= 0.5f); } } } }); DV.CabControls.ControlImplBase fanCtrl = instance.fanSwitchButton.GetComponent <DV.CabControls.ControlImplBase>(); fanCtrl.ValueChanged += (e => { if (PlayerManager.Car == null || PlayerManager.Car.trainset == null) { return; } for (int i = 0; i < PlayerManager.Car.trainset.cars.Count; i++) { TrainCar car = PlayerManager.Car.trainset.cars[i]; if (PlayerManager.Car.Equals(car)) { continue; } if (car.carType == TrainCarType.LocoShunter) { LocoControllerShunter locoController = car.GetComponent <LocoControllerShunter>(); if (locoController) { locoController.SetFan(e.newValue >= 0.5f); } } else if (car.carType == TrainCarType.LocoDiesel) { LocoControllerDiesel locoController = car.GetComponent <LocoControllerDiesel>(); if (locoController) { locoController.SetFan(e.newValue >= 0.5f); } } } }); }