Exemple #1
0
    public virtual void Setup(UserInterfaceSetup ui, RosBridgeConnector connector, VehicleConfig config)
    {
        Connector = connector;
        UI        = ui;
        var bridge = connector.Bridge;

        ui.PositionReset.RobotController = CarController;

        ui.SensorEffectsToggle.onValueChanged.AddListener(enabled => ToggleSensorEffect(enabled));

        // ui.WheelScale.onValueChanged.AddListener(value =>
        // {
        //     try
        //     {
        //         CarController.SetWheelScale(float.Parse(value));
        //     }
        //     catch (System.Exception)
        //     {
        //         Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
        //     }
        // });

        // Cameras.ForEach(c =>
        // {
        //     var pp = c.GetComponent<PostProcessingListener>();
        //     if (pp != null)
        //     {
        //         ui.CameraSaturation.onValueChanged.AddListener(x =>
        //         {
        //             pp.SetSaturationValue(x);
        //         });
        //     }
        // });

        ui.HighQualityRendering.onValueChanged.AddListener(enabled =>
        {
            FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = enabled;
            CameraMan?.SetHighQualityRendering(enabled);
        });

        ui.TrafficToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <TrafSpawner>()?.ReSpawnTrafficCars();
            }
            else
            {
                FindObjectOfType <TrafSpawner>()?.KillTrafficCars();
            }

            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficToggle.onValueChanged;
                    otherUI.TrafficToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficToggle.isOn           = enabled;
                    otherUI.TrafficToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.PedestriansToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <PedestrianManager>()?.SpawnNPCPedestrians();
            }
            else
            {
                FindObjectOfType <PedestrianManager>()?.KillNPCPedestrians();
            }

            //hack to sync toggle value among car UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.PedestriansToggle.onValueChanged;
                    otherUI.PedestriansToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.PedestriansToggle.isOn           = enabled;
                    otherUI.PedestriansToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.SteerwheelFeedback.onValueChanged.AddListener(enabled =>
        {
            var steerwheels = FindObjectsOfType <SteeringWheelInputController>();
            foreach (var steerwheel in steerwheels)
            {
                steerwheel.useFeedback = enabled;
            }
        });

        foreach (var item in NeedsBridge)
        {
            if (item == null)
            {
                continue;
            }
            var a = item as Ros.IRosClient;
            a.OnRosBridgeAvailable(bridge);
        }

        ui.AddTweakables(Tweakables);

        if (config != null)
        {
            ui.ToggleTweakable(Tweakables, "Lidar", config.enable_lidar);
            ui.ToggleTweakable(Tweakables, "GPS", config.enable_gps);
            ui.ToggleTweakable(Tweakables, "IMU", config.enable_imu);
            ui.ToggleTweakable(Tweakables, "Main Camera", config.enable_main_camera);
            ui.ToggleTweakable(Tweakables, "Telephoto Camera", config.enable_telephoto_camera);

            ui.HighQualityRendering.isOn = config.enable_high_quality_rendering;
            ui.SensorEffectsToggle.isOn  = config.enable_sensor_effects;
        }
    }
Exemple #2
0
    public virtual void Setup(UserInterfaceSetup ui, RosBridgeConnector connector, VehicleConfig config)
    {
        // needed for npc
        foreach (Transform child in transform)
        {
            if (child.CompareTag("MainCamera"))
            {
                mainCamera = child.GetComponent <Camera>();
            }
        }

        Connector = connector;
        UI        = ui;
        var bridge = connector.Bridge;

        ui.agentController = agentController;

        ui.SensorEffectsToggle.onValueChanged.AddListener(enabled => ToggleSensorEffect(enabled));

        // ui.WheelScale.onValueChanged.AddListener(value =>
        // {
        //     try
        //     {
        //         CarController.SetWheelScale(float.Parse(value));
        //     }
        //     catch (System.Exception)
        //     {
        //         Debug.Log("ROS Wheel Force Scaler: Please input valid number!");
        //     }
        // });

        // Cameras.ForEach(c =>
        // {
        //     var pp = c.GetComponent<PostProcessingListener>();
        //     if (pp != null)
        //     {
        //         ui.CameraSaturation.onValueChanged.AddListener(x =>
        //         {
        //             pp.SetSaturationValue(x);
        //         });
        //     }
        // });

        ui.LowQualityRendering.onValueChanged.AddListener(useLowQuality =>
        {
            FollowCamera.GetComponent <PostProcessingBehaviour>().enabled = !useLowQuality;
            CameraMan?.SetHighQualityRendering(!useLowQuality);
        });
        ui.LowQualityRendering.onValueChanged.Invoke(ui.LowQualityRendering.isOn);

        ui.TrafficToggle.onValueChanged.AddListener(enabled =>
        {
            FindObjectOfType <NPCManager>()?.ToggleNPCS(enabled);

            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficToggle.onValueChanged;
                    otherUI.TrafficToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficToggle.isOn           = enabled;
                    otherUI.TrafficToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.TrafficPhysicsModeToggle.onValueChanged.AddListener(enabled =>
        {
            FindObjectOfType <NPCManager>()?.ToggleNPCPhysicsMode(enabled);
            //hack to sync toggle value among cars UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.TrafficPhysicsModeToggle.onValueChanged;
                    otherUI.TrafficPhysicsModeToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.TrafficPhysicsModeToggle.isOn           = enabled;
                    otherUI.TrafficPhysicsModeToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.PedestriansToggle.onValueChanged.AddListener(enabled =>
        {
            if (enabled)
            {
                FindObjectOfType <PedestrianManager>()?.SpawnPedestrians();
            }
            else
            {
                FindObjectOfType <PedestrianManager>()?.KillPedestrians();
            }

            //hack to sync toggle value among car UIs
            {
                foreach (var otherUI in FindObjectsOfType <UserInterfaceSetup>())
                {
                    if (otherUI == ui)
                    {
                        continue;
                    }

                    var oldEvent = otherUI.PedestriansToggle.onValueChanged;
                    otherUI.PedestriansToggle.onValueChanged = new UnityEngine.UI.Toggle.ToggleEvent();
                    otherUI.PedestriansToggle.isOn           = enabled;
                    otherUI.PedestriansToggle.onValueChanged = oldEvent;
                }
            }
        });

        ui.SteerwheelFeedback.onValueChanged.AddListener(enabled =>
        {
            var steerwheels = FindObjectsOfType <SteeringWheelInputController>();
            foreach (var steerwheel in steerwheels)
            {
                steerwheel.useFeedback = enabled;
            }
        });

        foreach (var item in NeedsBridge)
        {
            if (item == null)
            {
                continue;
            }
            var a = item as Comm.BridgeClient;
            a.OnBridgeAvailable(bridge);
        }

        ui.AddTweakables(Tweakables);

        if (config != null)
        {
            ui.ToggleTweakable(Tweakables, "Lidar", config.enable_lidar);
            ui.ToggleTweakable(Tweakables, "GPS", config.enable_gps);
            ui.ToggleTweakable(Tweakables, "IMU", config.enable_imu);
            ui.ToggleTweakable(Tweakables, "Main Camera", config.enable_main_camera);
            ui.ToggleTweakable(Tweakables, "Telephoto Camera", config.enable_telephoto_camera);

            ui.LowQualityRendering.isOn = !config.enable_high_quality_rendering;
            ui.SensorEffectsToggle.isOn = config.enable_sensor_effects;
        }

        if (config != null)
        {
            if (StaticConfigManager.Instance.staticConfig.initialized && ROSAgentManager.Instance.currentMode == StartModeTypes.StaticConfig)
            {
                ui.CheckStaticConfigTraffic();
            }
        }

        // CES
        CarInputController cc = GetComponent <CarInputController>();

        if (cc != null)
        {
            cc[InputEvent.TOGGLE_SENSOR_EFFECTS].Press += ToggleSensorEffect;
            cc[InputEvent.TOGGLE_TRAFFIC].Press        += ToggleTraffic;
            cc[InputEvent.TOGGLE_UI].Press             += ToggleUI;
        }
    }