Esempio n. 1
0
        public override void OnBridgeSetup(IBridge bridge)
        {
            bridge.AddReader <VehicleStateData>(Topic, data =>
            {
                if (data != null)
                {
                    if (StateData.Blinker != data.Blinker)
                    {
                        if (data.Blinker == 0)
                        {
                            if (Actions.LeftTurnSignal)
                            {
                                Actions.LeftTurnSignal = false;
                            }
                            if (Actions.RightTurnSignal)
                            {
                                Actions.RightTurnSignal = false;
                            }
                            if (Actions.HazardLights)
                            {
                                Actions.HazardLights = false;
                            }
                        }
                        else if (data.Blinker == 1)
                        {
                            Actions.LeftTurnSignal = true;
                        }
                        else if (data.Blinker == 2)
                        {
                            Actions.RightTurnSignal = true;
                        }
                        else if (data.Blinker == 3)
                        {
                            Actions.HazardLights = true;
                        }
                    }
                    if (StateData.HeadLight != data.HeadLight)
                    {
                        if (data.HeadLight == 0)
                        {
                            Actions.CurrentHeadLightState = VehicleActions.HeadLightState.OFF;
                        }
                        else if (data.HeadLight == 1)
                        {
                            Actions.CurrentHeadLightState = VehicleActions.HeadLightState.LOW;
                        }
                        else if (data.HeadLight == 2)
                        {
                            Actions.CurrentHeadLightState = VehicleActions.HeadLightState.HIGH;
                        }
                    }
                    if (StateData.Gear != data.Gear)
                    {
                        if (data.Gear == 1)
                        {
                            Dynamics.ShiftReverse();
                        }
                        else if (data.Gear == 0)
                        {
                            Dynamics.ShiftFirstGear();
                        }
                    }
                    if (StateData.HandBrake != data.HandBrake)
                    {
                        if (data.HandBrake == true)
                        {
                            Dynamics.SetHandBrake(true);
                        }
                        else
                        {
                            Dynamics.SetHandBrake(false);
                        }
                    }

                    StateData = data;
                }
            });
        }
        public override void OnBridgeSetup(BridgeInstance bridge)
        {
            bridge.AddSubscriber <VehicleStateData>(Topic, data =>
            {
                if (Time.timeScale == 0f)
                {
                    return;
                }

                if (data != null)
                {
                    if (StateData.Blinker != data.Blinker)
                    {
                        if (data.Blinker == 0)
                        {
                            if (Actions.LeftTurnSignal)
                            {
                                Actions.LeftTurnSignal = false;
                            }
                            if (Actions.RightTurnSignal)
                            {
                                Actions.RightTurnSignal = false;
                            }
                            if (Actions.HazardLights)
                            {
                                Actions.HazardLights = false;
                            }
                        }
                        else if (data.Blinker == 1)
                        {
                            Actions.LeftTurnSignal = true;
                        }
                        else if (data.Blinker == 2)
                        {
                            Actions.RightTurnSignal = true;
                        }
                        else if (data.Blinker == 3)
                        {
                            Actions.HazardLights = true;
                        }
                    }
                    if (StateData.HeadLight != data.HeadLight)
                    {
                        if (data.HeadLight == 0)
                        {
                            Actions.CurrentHeadLightState = HeadLightState.OFF;
                        }
                        else if (data.HeadLight == 1)
                        {
                            Actions.CurrentHeadLightState = HeadLightState.LOW;
                        }
                        else if (data.HeadLight == 2)
                        {
                            Actions.CurrentHeadLightState = HeadLightState.HIGH;
                        }
                    }
                    if (StateData.Gear != data.Gear)
                    {
                        if (data.Gear == (byte)GearPosition.Reverse)
                        {
                            Dynamics.ShiftReverseAutoGearBox();
                        }
                        else if (data.Gear == (byte)GearPosition.Drive)
                        {
                            Dynamics.ShiftFirstGear();
                        }
                    }
                    if (StateData.HandBrake != data.HandBrake)
                    {
                        if (data.HandBrake == true)
                        {
                            Dynamics.SetHandBrake(true);
                        }
                        else
                        {
                            Dynamics.SetHandBrake(false);
                        }
                    }

                    StateData = data;
                }
            });
        }
Esempio n. 3
0
 void Start()
 {
     Actions   = GetComponentInParent <VehicleActions>();
     Dynamics  = GetComponentInParent <VehicleDynamics>();
     StateData = new VehicleStateData();
 }
 protected override void Initialize()
 {
     Actions   = GetComponentInParent <VehicleActions>();
     Dynamics  = GetComponentInParent <IVehicleDynamics>();
     StateData = new VehicleStateData();
 }