Exemple #1
0
 public void FillOptionFields()
 {
     foreach (string key in keyToOptionField.Keys)
     {
         keyToOptionField[key].text = RobotOptions.GetValue(key);
     }
     foreach (string key in keyToToggleField.Keys)
     {
         keyToToggleField[key].isOn = RobotOptions.GetValue(key) == "True";
     }
 }
Exemple #2
0
    public void SelectRobot(RobotScriptableObject activeRobot)
    {
        MenuController.activeRobot = activeRobot;
        PlayerPrefs.SetString("lastRobot", activeRobot.robotName);

        // Delete existing options
        foreach (GameObject option in options)
        {
            Destroy(option);
        }

        // Make new ones for the new robot
        foreach (Option option in activeRobot.options)
        {
            if (option.type == OptionType.String)
            {
                GameObject optionObj = Instantiate(optionPrefab, optionEntryParent);
                options.Add(optionObj);

                TextMeshProUGUI text = optionObj.GetComponentInChildren <TextMeshProUGUI>();
                text.text = option.name;

                TMP_InputField input_field = optionObj.GetComponentInChildren <TMP_InputField>();
                input_field.text = RobotOptions.GetValue(activeRobot.robotName + option.name);
                input_field.onEndEdit.AddListener(delegate
                {
                    RobotOptions.SetValue(activeRobot.robotName + option.name, input_field.text);
                });
                keyToOptionField[activeRobot.robotName + option.name] = input_field;
            }
            else if (option.type == OptionType.Boolean)
            {
                GameObject optionObj = Instantiate(optionTogglePrefab, optionEntryParent);
                options.Add(optionObj);

                Toggle toggle = optionObj.GetComponent <Toggle>();
                toggle.onValueChanged.AddListener(delegate
                {
                    RobotOptions.SetValue(activeRobot.robotName + option.name, toggle.isOn ? "True" : "False");
                });

                if (RobotOptions.GetValue(activeRobot.robotName + option.name) == "True")
                {
                    toggle.isOn = true;
                }


                TextMeshProUGUI text = optionObj.GetComponentInChildren <TextMeshProUGUI>();
                text.text = option.name;
                keyToToggleField[activeRobot.robotName + option.name] = toggle;
            }
        }
    }
        void Awake()
        {
            simpleCarController  = this.GetComponent <SimpleCarController>();
            rosConnector         = this.GetComponent <RosConnector>();
            imagePublisher       = this.GetComponent <ImagePublisher>();
            driveStatusPublisher = this.GetComponent <DriveStatusPublisher>();
            motorsSubscriber     = this.GetComponent <NRCMotorsSubscriber>();

            simpleCarController.useController = !RobotOptions.GetValue(robotName + "Autonomous").Equals("True");
            rosConnector.RosBridgeServerUrl   = "ws://" + RobotOptions.GetValue(robotName + "ROS Bridge IP");
            imagePublisher.Topic       = RobotOptions.GetValue(robotName + "Camera Topic");
            driveStatusPublisher.Topic = RobotOptions.GetValue(robotName + "Drive Status Topic");
            motorsSubscriber.Topic     = RobotOptions.GetValue(robotName + "Motors Topic");
        }
        void Awake()
        {
            simpleCarController = this.GetComponent <SimpleCarController>();
            imagePublisher      = this.GetComponent <ImagePublisher>();
            laserScanPublisher  = this.GetComponent <LaserScanPublisher>();
            iMUPublisher        = this.GetComponent <IMUPublisher>();
            velocityPublisher   = this.GetComponent <VelocityPublisher>();
            gPSPublisher        = this.GetComponent <GPSPublisher>();
            motorsSubscriber    = this.GetComponent <IGVCMotorsSubscriber>();

            simpleCarController.useController = !RobotOptions.GetValue(robotName + "Autonomous").Equals("True");
            //rosConnector.RosBridgeServerUrl = "ws://" + RobotOptions.GetValue(robotName + "ROS Bridge IP");
            if (RobotOptions.Exists(robotName + "Camera Topic"))
            {
                imagePublisher.Topic = RobotOptions.GetValue(robotName + "Camera Topic");
            }
            if (RobotOptions.Exists(robotName + "Show Camera View") && RobotOptions.GetValue(robotName + "Show Camera View").Equals("True"))
            {
                robotCamera.targetDisplay = 0;
                robotCamera.enabled       = true;
                mainCamera.enabled        = false;

                // If we are publishing the camera, we need to duplicate it because the publishing script
                // will override the camera output.
                if (RobotOptions.GetValue(robotName + "Publish Camera").Equals("True"))
                {
                    GameObject robotCameraDupe = Instantiate(robotCamera.gameObject, robotCamera.gameObject.transform.parent);
                }
            }
            if (RobotOptions.GetValue(robotName + "Publish Camera").Equals("True"))
            {
                imagePublisher.enabled = true;
                robotCamera.enabled    = true;
            }
            laserScanPublisher.Topic = RobotOptions.GetValue(robotName + "Laser Scan Topic");
            iMUPublisher.Topic       = RobotOptions.GetValue(robotName + "IMU Topic");
            velocityPublisher.Topic  = RobotOptions.GetValue(robotName + "Velocity Topic");
            gPSPublisher.Topic       = RobotOptions.GetValue(robotName + "GPS Topic");
            motorsSubscriber.Topic   = RobotOptions.GetValue(robotName + "Motors Topic");
        }
Exemple #5
0
    public void Start()
    {
        // Load up Robot Options
        if (!alreadyInit)
        {
            RobotOptions.LoadSaved(robots);
        }
        else
        {
            FillOptionFields();
        }

        string robotNameToLoad = PlayerPrefs.GetString("lastRobot", robots[0].robotName);
        int    levelIdToLoad   = PlayerPrefs.GetInt("lastLevel", levels[0].levelId);

        // Generate level toggles
        foreach (LevelScriptableObject level in levels)
        {
            GameObject levelToggle = Instantiate(togglePrefab, togglesParent);

            Toggle toggle = levelToggle.GetComponent <Toggle>();
            toggle.onValueChanged.AddListener(delegate
            {
                SelectLevel(level);
            });
            toggle.group = togglesGroup;

            if (level.levelId == levelIdToLoad)
            {
                activeLevel = level;
                toggle.isOn = true;
            }

            TextMeshProUGUI text = levelToggle.GetComponentInChildren <TextMeshProUGUI>();
            text.text = level.levelName;
        }
        // Generate robot toggles
        foreach (RobotScriptableObject robot in robots)
        {
            GameObject robotToggle = Instantiate(togglePrefab, robotsParent);

            Toggle toggle = robotToggle.GetComponent <Toggle>();
            toggle.onValueChanged.AddListener(delegate
            {
                SelectRobot(robot);
            });
            toggle.group = robotsGroup;

            if (robot.robotName == robotNameToLoad)
            {
                activeRobot = robot;
                toggle.isOn = true;
            }


            TextMeshProUGUI text = robotToggle.GetComponentInChildren <TextMeshProUGUI>();
            text.text = robot.robotName;
        }

        alreadyInit = true;

        if (RosConnector.instance.IsConnected.WaitOne(0))
        {
            RunButton.interactable = true;
            RunButton.GetComponentInChildren <TextMeshProUGUI>().text = "Run";
        }
    }
Exemple #6
0
    public void DefaultOptions()
    {
        RobotOptions.LoadDefaults(robots);

        FillOptionFields();
    }
Exemple #7
0
    public void LoadOptions()
    {
        RobotOptions.LoadSaved(robots);

        FillOptionFields();
    }
Exemple #8
0
 public void SaveOptions()
 {
     RobotOptions.Save();
 }