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);
                }
            });
        }
示例#2
0
        static void Postfix(LocoControllerBase __instance)
        {
            // use switch on fireman's side of cab instead of reverser for steam loco
            if (__instance.train.carType == TrainCarType.LocoSteamHeavy)
            {
                return;
            }

            LocoLights locoLights = __instance.train.transform.gameObject.GetComponent <LocoLights>();

            if (locoLights == null)
            {
                return;
            }

            locoLights.SetDirection(__instance.reverser);
        }
        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);
                }
            });
        }