/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count) { robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); // TODO: The camera is a bit weird when changing robots. Fix that. Then test other aspects of the simulator and fix anything else that needs fixing. MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); ActiveRobot = null; SwitchActiveRobot(); int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } } }
/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count && SpawnedRobots.Count > 1) { robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); if (SpawnedRobots[index].RobotHasManipulator) { GameObject.Destroy(SpawnedRobots[index].ManipulatorObject); } GameObject.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); ActiveRobot = null; SwitchActiveRobot(); int i = 0; foreach (Robot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } } }
/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count && SpawnedRobots.Count > 1) { robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); int isMixAndMatch = PlayerPrefs.GetInt("mixAndMatch"); //0 is false, 1 is true if (isMixAndMatch == 1 && SpawnedRobots[index].robotHasManipulator == 1) { GameObject.Destroy(SpawnedRobots[index].manipulatorObject); } GameObject.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); activeRobot = null; SwitchActiveRobot(); int i = 0; foreach (Robot robot in SpawnedRobots) { robot.controlIndex = i; i++; } } }
/// <summary> /// If there are two robots or more, remove and delete the robot at that index /// </summary> public void RemoveRobot(int index) { if (index < SpawnedRobots.Count) { //remove attached sensors/cameras robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); SpawnedRobots.RemoveAt(index); ActiveRobot = null; SwitchActiveRobot(index < SpawnedRobots.Count() ? index : SpawnedRobots.Count() - 1); //switch to either old location or last active robot int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } } }
/// <summary> /// Changes the active robot to a new robot with a given directory /// </summary> /// <param name="directory"></param> /// <returns>whether the process was successful</returns> public bool ChangeRobot(string directory, bool isMixAndMatch) { sensorManager.RemoveSensorsFromRobot(ActiveRobot); sensorManagerGUI.ShiftOutputPanels(); sensorManagerGUI.EndProcesses(); int index = SpawnedRobots.IndexOf(ActiveRobot); robotCameraManager.RemoveCamerasFromRobot(SpawnedRobots[index]); sensorManager.RemoveSensorsFromRobot(SpawnedRobots[index]); MaMRobot mamRobot = SpawnedRobots[index] as MaMRobot; if (mamRobot != null && mamRobot.RobotHasManipulator) { UnityEngine.Object.Destroy(mamRobot.ManipulatorObject); } UnityEngine.Object.Destroy(SpawnedRobots[index].gameObject); ActiveRobot = null; if (LoadRobot(directory, isMixAndMatch, index)) { DynamicCamera.ControlEnabled = true; int i = 0; foreach (SimulatorRobot robot in SpawnedRobots) { robot.ControlIndex = i; i++; } return(true); } return(false); }