/// <summary> /// Add a new camera to the robot using the default position (0, 0.5, 0) and rotation /// </summary> /// <returns></returns> public GameObject AddCamera(SimulatorRobot robot, Transform anchor) { GameObject newCamera = new GameObject("RobotCamera_" + robotCameraList.Count); newCamera.AddComponent <UnityEngine.Camera>(); newCamera.transform.parent = anchor; newCamera.transform.localPosition = new Vector3(0f, 0f, 0f); newCamera.transform.localRotation = Quaternion.identity; RobotCamera configuration = newCamera.AddComponent <RobotCamera>(); configuration.UpdateConfiguration(); //Set the camera parent robot, which is necessary when changing robot and restoring the configuration configuration.SetParentRobot(robot); newCamera.SetActive(false); //Make sure current camera is the first one on the list if (robotCameraList.Count == 0) { CurrentCamera = newCamera; } robotCameraList.Add(newCamera); return(newCamera); }
/// <summary> /// Add a new camera to the robot /// </summary> /// <param name="anchor"></param> The robot node to which the camera attaches /// <param name="positionOffset"></param> /// <param name="rotationOffset"></param> /// <returns></returns> public GameObject AddCamera(SimulatorRobot robot, Transform anchor, Vector3 positionOffset, Vector3 rotationOffset) { GameObject newCamera = new GameObject("RobotCamera_" + robotCameraList.Count); newCamera.AddComponent <UnityEngine.Camera>(); newCamera.transform.parent = anchor; newCamera.transform.localPosition = positionOffset; newCamera.transform.localRotation = Quaternion.Euler(rotationOffset); newCamera.GetComponent <UnityEngine.Camera>().fieldOfView = 60; RobotCamera configuration = newCamera.AddComponent <RobotCamera>(); configuration.UpdateConfiguration(); //Set the camera parent robot, which is necessary when changing robot and restoring the configuration configuration.SetParentRobot(robot); newCamera.SetActive(false); if (robotCameraList.Count == 0) { CurrentCamera = newCamera; } robotCameraList.Add(newCamera); return(newCamera); }
/// <summary> /// Detach the robot camera from a given robot in preparation for changing robot or other operation that needs to take out a specific group of robot camera /// </summary> /// <param name="parent"></param> A robot where cameras are going to be detached from public void DetachCamerasFromRobot(SimulatorRobot parent) { List <GameObject> detachingCameras = GetRobotCamerasFromRobot(parent); foreach (GameObject camera in detachingCameras) { camera.GetComponent <RobotCamera>().DetachCamera(); } }
/// <summary> /// Get a list of sensors attached to the given robot /// </summary> /// <param name="robot"></param> The robot where sensors are attached to /// <returns></returns> A list of sensors attached to the robot public List <GameObject> GetSensorsFromRobot(SimulatorRobot robot) { List <GameObject> sensorsOnRobot = new List <GameObject>(); foreach (GameObject sensor in activeSensorList) { if (sensor.GetComponent <SensorBase>().Robot.Equals(robot)) { sensorsOnRobot.Add(sensor); } } return(sensorsOnRobot); }
/// <summary> /// Return a list of robot cameras attached to a given robot /// </summary> /// <param name="parent"></param> A robot on which cameras are attached to /// <returns></returns> A list of camera attach to that robot public List <GameObject> GetRobotCamerasFromRobot(SimulatorRobot parent) { List <GameObject> camerasOnRobot = new List <GameObject>(); foreach (GameObject camera in robotCameraList) { RobotCamera config = camera.GetComponent <RobotCamera>(); if (config.robot.Equals(parent)) { camerasOnRobot.Add(camera); } } return(camerasOnRobot); }
/// <summary> /// Remove all sensors attached to the given robot and destroy them, reset all lists /// </summary> /// <param name="robot"></param> The robot where sensors are attached to public void RemoveSensorsFromRobot(SimulatorRobot robot) { List <GameObject> sensorsOnRobot = GetSensorsFromRobot(robot); foreach (GameObject removingSensors in sensorsOnRobot) { if (activeSensorList.Contains(removingSensors)) { activeSensorList.Remove(removingSensors); removingSensors.transform.parent = null; Destroy(removingSensors.gameObject); inactiveSensorList.Add(removingSensors); } } }
/// <summary> /// Remove the current sensor from the robot /// </summary> /// <param name="robot"></param> public void RemoveSensorsFromRobot(SimulatorRobot robot) { List <GameObject> sensorsOnRobot = sensorManager.GetSensorsFromRobot(robot); foreach (GameObject removingSensors in sensorsOnRobot) { string type = removingSensors.GetComponent <SensorBase>().sensorType; Destroy(removingSensors); sensorManager.RemoveSensor(removingSensors, type); ShiftOutputPanels(); if (currentSensor != null && currentSensor.Equals(removingSensors.GetComponent <SensorBase>())) { currentSensor = null; EndProcesses(); } tabStateMachine.FindState <SensorToolbarState>().RemoveSensorFromDropdown(type, sensorManager.ultrasonicList, sensorManager.beamBreakerList, sensorManager.gyroList); } }
/// <summary> /// Remove all cameras from a given robot, used when a robot is removed. Use DetachCamerasFromRobot when changing a robot! /// </summary> /// <param name="parent"></param> The robot whose cameras you want to remove public void RemoveCamerasFromRobot(SimulatorRobot parent) { List <GameObject> removingCameras = GetRobotCamerasFromRobot(parent); //Take out the camera indicator in case it gets destroyed with one of the robots cameraIndicator.transform.parent = robotCameraListObject.transform; foreach (GameObject camera in removingCameras) { //Remove those useless cameras from the list and destroy them if (robotCameraList.Contains(camera)) { robotCameraList.Remove(camera); Destroy(camera); } } //Reset the current camera to the first one on the list in case the current one gets destroyed already if (robotCameraList.Count > 0) { CurrentCamera = robotCameraList[0]; } }
/// <summary> /// Remove the current sensor from the robot /// </summary> /// <param name="robot"></param> public void RemoveSensorsFromRobot(SimulatorRobot robot) { List <GameObject> sensorsOnRobot = sensorManager.GetSensorsFromRobot(robot); foreach (GameObject removingSensors in sensorsOnRobot) { string type = removingSensors.GetComponent <SensorBase>().sensorType; Destroy(removingSensors); sensorManager.RemoveSensor(removingSensors, type); ShiftOutputPanels(); if (currentSensor != null && currentSensor.Equals(removingSensors.GetComponent <SensorBase>())) { currentSensor = null; EndProcesses(); } tabStateMachine.FindState <SensorToolbarState>().RemoveSensorFromDropdown(type, sensorManager.ultrasonicList, sensorManager.beamBreakerList, sensorManager.gyroList); } AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.SensorTab, AnalyticsLedger.EventAction.Removed, "Sensors", AnalyticsLedger.getMilliseconds().ToString()); }
/// <summary> /// Set the parent robot of the robot cameras /// </summary> /// <param name="robot"></param> public void SetParentRobot(SimulatorRobot robot) { this.robot = robot; }