static IEnumerator <object> AttachListeners() { yield return((object)null); var rotary02 = GameObjectUtils.FindObject(instance.transform.gameObject, "C headlights dash_rotary02"); DV.CabControls.ControlImplBase lightCtrl = rotary02.gameObject.GetComponent <DV.CabControls.ControlImplBase>(); if (PlayerManager.Car.carType == TrainCarType.LocoShunter) { locoLights = PlayerManager.Car.GetComponent <LocoLights>(); } if (locoLights != null) { lightCtrl.SetValue(locoLights.IsOn ? 1f : 0f); } lightCtrl.ValueChanged += (e => { if (locoLights != null) { locoLights.SetLights(e.newValue > 0.5f); } }); }
static IEnumerator AttachListeners() { yield return(null); var light_switch = GameObjectUtils.FindObject(instance.transform.gameObject, "C light lever"); DV.CabControls.ControlImplBase lightCtrl = light_switch .gameObject.GetComponent <DV.CabControls.ControlImplBase>(); if (PlayerManager.Car.carType == TrainCarType.LocoSteamHeavy) { locoLights = PlayerManager.Car.GetComponent <LocoLights>(); } var isInitialized = Traverse.Create(lightCtrl).Field("isInitialized"); Main.Log("pausing until Lever is initialized"); while (!isInitialized.GetValue <bool>()) { yield return(null); } Main.Log("Lever is initialized; resuming"); if (locoLights != null) { float position = DirectionToLeverPosition(locoLights.IsOn ? locoLights.Direction : 0f); lightCtrl.SetValue(position); } lightCtrl.ValueChanged += (e => { if (locoLights != null) { float direction = LeverPositionToDirection(e.newValue); locoLights.SetLights(Mathf.Abs(direction) > 0.25f); locoLights.SetDirection(Mathf.Abs(direction) > 0.75f ? direction : 0f); } }); }