/// <summary> /// Finds all the necessary UI elements that need to be updated/modified /// </summary> private void FindElements() { canvas = GameObject.Find("Canvas"); freeroamCameraWindow = AuxFunctions.FindObject(canvas, "FreeroamPanel"); spawnpointWindow = AuxFunctions.FindObject(canvas, "SpawnpointPanel"); swapWindow = AuxFunctions.FindObject(canvas, "SwapPanel"); wheelPanel = AuxFunctions.FindObject(canvas, "WheelPanel"); driveBasePanel = AuxFunctions.FindObject(canvas, "DriveBasePanel"); manipulatorPanel = AuxFunctions.FindObject(canvas, "ManipulatorPanel"); addRobotPanel = AuxFunctions.FindObject("MultiplayerPanel"); driverStationPanel = AuxFunctions.FindObject(canvas, "DriverStationPanel"); changeRobotPanel = AuxFunctions.FindObject(canvas, "ChangeRobotPanel"); robotListPanel = AuxFunctions.FindObject(changeRobotPanel, "RobotListPanel"); changeFieldPanel = AuxFunctions.FindObject(canvas, "ChangeFieldPanel"); inputManagerPanel = AuxFunctions.FindObject(canvas, "InputManagerPanel"); orientWindow = AuxFunctions.FindObject(canvas, "OrientWindow"); resetDropdown = GameObject.Find("Reset Robot Dropdown"); exitPanel = AuxFunctions.FindObject(canvas, "ExitPanel"); loadingPanel = AuxFunctions.FindObject(canvas, "LoadingPanel"); unitConversionButton = AuxFunctions.FindObject(canvas, "UnitConversionButton"); sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); mixAndMatchPanel = AuxFunctions.FindObject(canvas, "MixAndMatchPanel"); }
/// <summary> /// Called after Awake() when the script instance is enabled. /// Initializes variables then loads the field and robot as well as setting up replay features. /// </summary> public override void Start() { //getting bullet physics information physicsWorld = BPhysicsWorld.Get(); ((DynamicsWorld)physicsWorld.world).SetInternalTickCallback(BRobotManager.Instance.UpdateRaycastRobots); lastFrameCount = physicsWorld.frameCount; //setting up replay Trackers = new List <Tracker>(); CollisionTracker = new CollisionTracker(this); //starts a new instance of unity packet which receives packets from the driver station unityPacket = new UnityPacket(); unityPacket.Start(); //loads all the controls Controls.Load(); //If a replay has been selected, load the replay. Otherwise, load the field and robot. string selectedReplay = PlayerPrefs.GetString("simSelectedReplay"); SpawnedRobots = new List <Robot>(); if (string.IsNullOrEmpty(selectedReplay)) { Tracking = true; Debug.Log(LoadField(PlayerPrefs.GetString("simSelectedField")) ? "Load field success!" : "Load field failed."); Debug.Log(LoadRobot(PlayerPrefs.GetString("simSelectedRobot")) ? "Load robot success!" : "Load robot failed."); int isMixAndMatch = PlayerPrefs.GetInt("MixAndMatch", 0); // 0 is false, 1 is true int hasManipulator = PlayerPrefs.GetInt("hasManipulator"); if (isMixAndMatch == 1 && hasManipulator == 1) { Debug.Log(LoadManipulator(PlayerPrefs.GetString("simSelectedManipulator")) ? "Load manipulator success" : "Load manipulator failed"); } } else { awaitingReplay = true; LoadReplay(selectedReplay); } //initializes the dynamic camera dynamicCameraObject = GameObject.Find("Main Camera"); dynamicCamera = dynamicCameraObject.AddComponent <DynamicCamera>(); DynamicCamera.MovingEnabled = true; sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManagerGUI = GameObject.Find("StateMachine").GetComponent <SensorManagerGUI>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); }
/// <summary> /// Finds all the necessary UI elements that need to be updated/modified /// </summary> private void FindElements() { canvas = GameObject.Find("Canvas"); resetUI = Auxiliary.FindGameObject("ResetRobotSpawnpointUI"); freeroamCameraWindow = Auxiliary.FindObject(canvas, "FreeroamPanel"); overviewCameraWindow = Auxiliary.FindObject(canvas, "OverviewPanel"); spawnpointPanel = Auxiliary.FindObject(canvas, "SpawnpointPanel"); //multiplayerPanel = Auxiliary.FindObject(canvas, "MultiplayerPanel"); driverStationPanel = Auxiliary.FindObject(canvas, "DriverStationPanel"); changeRobotPanel = Auxiliary.FindObject(canvas, "ChangeRobotPanel"); robotListPanel = Auxiliary.FindObject(changeRobotPanel, "RobotListPanel"); changeFieldPanel = Auxiliary.FindObject(canvas, "ChangeFieldPanel"); inputManagerPanel = Auxiliary.FindObject(canvas, "InputManagerPanel"); bindedKeyPanel = Auxiliary.FindObject(canvas, "BindedKeyPanel"); checkSavePanel = Auxiliary.FindObject(canvas, "CheckSavePanel"); unitConversionSwitch = Auxiliary.FindObject(canvas, "UnitConversionSwitch"); hotKeyPanel = Auxiliary.FindObject(canvas, "HotKeyPanel"); hotKeyButton = Auxiliary.FindObject(canvas, "DisplayHotKeyButton"); orientWindow = Auxiliary.FindObject(resetUI, "OrientWindow"); resetDropdown = GameObject.Find("Reset Robot Dropdown"); exitPanel = Auxiliary.FindObject(canvas, "ExitPanel"); loadingPanel = Auxiliary.FindObject(canvas, "LoadingPanel"); analyticsPanel = Auxiliary.FindObject(canvas, "AnalyticsPanel"); sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); robotCameraGUI = GetComponent <RobotCameraGUI>(); mixAndMatchPanel = Auxiliary.FindObject(canvas, "MixAndMatchPanel"); changePanel = Auxiliary.FindObject(canvas, "ChangePanel"); addPanel = Auxiliary.FindObject(canvas, "AddPanel"); // tab and toolbar system components tabs = Auxiliary.FindGameObject("Tabs"); emulationTab = Auxiliary.FindObject(tabs, "EmulationTab"); tabStateMachine = tabs.GetComponent <StateMachine>(); CheckControlPanel(); LinkToolbars(); tabStateMachine.ChangeState(new MainToolbarState()); currentTab = "HomeTab"; ButtonCallbackManager.RegisterButtonCallbacks(tabStateMachine, canvas); ButtonCallbackManager.RegisterDropdownCallbacks(tabStateMachine, canvas); helpMenu = Auxiliary.FindObject(canvas, "Help"); overlay = Auxiliary.FindObject(canvas, "Overlay"); }
/// <summary> /// Find all robot camera related GUI elements in the canvas /// </summary> public void FindGUIElements() { canvas = GameObject.Find("Canvas"); sensorManagerGUI = GameObject.Find("StateMachine").GetComponent <SensorManagerGUI>(); //For robot camera view window robotCameraView = Resources.Load("Images/RobotCameraView") as RenderTexture; robotCameraViewWindow = AuxFunctions.FindObject(canvas, "RobotCameraPanelBorder"); //For robot camera manager robotCameraListObject = GameObject.Find("RobotCameraList"); robotCameraManager = robotCameraListObject.GetComponent <RobotCameraManager>(); //For camera indicator if (CameraIndicator == null) { CameraIndicator = AuxFunctions.FindObject(robotCameraListObject, "CameraIndicator"); } showCameraButton = AuxFunctions.FindObject(canvas, "ShowCameraButton"); //For camera position and attachment configuration configureCameraPanel = AuxFunctions.FindObject(canvas, "CameraConfigurationPanel"); configureRobotCameraButton = AuxFunctions.FindObject(canvas, "CameraConfigurationButton"); changeCameraNodeButton = AuxFunctions.FindObject(configureCameraPanel, "ChangeNodeButton"); cameraConfigurationModeButton = AuxFunctions.FindObject(configureCameraPanel, "ConfigurationMode"); cameraNodeText = AuxFunctions.FindObject(configureCameraPanel, "NodeText").GetComponent <Text>(); cancelNodeSelectionButton = AuxFunctions.FindObject(configureCameraPanel, "CancelNodeSelectionButton"); //For camera angle configuration cameraAnglePanel = AuxFunctions.FindObject(canvas, "CameraAnglePanel"); xAngleEntry = AuxFunctions.FindObject(cameraAnglePanel, "xAngleEntry"); yAngleEntry = AuxFunctions.FindObject(cameraAnglePanel, "yAngleEntry"); zAngleEntry = AuxFunctions.FindObject(cameraAnglePanel, "zAngleEntry"); showAngleButton = AuxFunctions.FindObject(configureCameraPanel, "ShowCameraAngleButton"); editAngleButton = AuxFunctions.FindObject(cameraAnglePanel, "EditButton"); //For field of view configuration cameraFOVPanel = AuxFunctions.FindObject(canvas, "CameraFOVPanel"); FOVEntry = AuxFunctions.FindObject(cameraFOVPanel, "FOVEntry"); showFOVButton = AuxFunctions.FindObject(configureCameraPanel, "ShowCameraFOVButton"); editFOVButton = AuxFunctions.FindObject(cameraFOVPanel, "EditButton"); lockPositionButton = AuxFunctions.FindObject(configureCameraPanel, "LockPositionButton"); lockAngleButton = AuxFunctions.FindObject(configureCameraPanel, "LockAngleButton"); lockFOVButton = AuxFunctions.FindObject(configureCameraPanel, "LockFOVButton"); }
/// <summary> /// Finds all the necessary UI elements that need to be updated/modified /// </summary> private void FindElements() { canvas = GameObject.Find("Canvas"); resetRobotUI = Auxiliary.FindGameObject("ResetRobotSpawnpointUI"); navigationTooltip = Auxiliary.FindObject("NavigationTooltipContainer"); overviewCameraWindow = Auxiliary.FindObject(canvas, "OverviewPanel"); //multiplayerPanel = Auxiliary.FindObject(canvas, "MultiplayerPanel"); driverStationPanel = Auxiliary.FindObject(canvas, "DriverStationPanel"); changeRobotPanel = Auxiliary.FindObject(canvas, "ChangeRobotPanel"); robotListPanel = Auxiliary.FindObject(changeRobotPanel, "RobotListPanel"); changeFieldPanel = Auxiliary.FindObject(canvas, "ChangeFieldPanel"); loadEmptyFieldButton = Auxiliary.FindObject(changeFieldPanel, "LoadEmptyButton"); resetDropdown = GameObject.Find("Reset Robot Dropdown"); exitPanel = Auxiliary.FindObject(canvas, "ExitPanel"); loadingPanel = Auxiliary.FindObject(canvas, "LoadingPanel"); sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); robotCameraGUI = GetComponent <RobotCameraGUI>(); mixAndMatchPanel = Auxiliary.FindObject(canvas, "MixAndMatchPanel"); changePanel = Auxiliary.FindObject(canvas, "ChangePanel"); addPanel = Auxiliary.FindObject(canvas, "AddPanel"); // tab and toolbar system components tabs = Auxiliary.FindGameObject("Tabs"); gamepieceTab = Auxiliary.FindObject(tabs, "DriverPracticeTab"); scoringTab = Auxiliary.FindObject(tabs, "ScoringTab"); tabStateMachine = tabs.GetComponent <StateMachine>(); betaWarningPanel = Auxiliary.FindObject(canvas, "BetaWarningPanel"); LinkToolbars(); tabStateMachine.ChangeState(new MainToolbarState()); currentTab = "HomeTab"; UICallbackManager.RegisterButtonCallbacks(tabStateMachine, canvas); UICallbackManager.RegisterDropdownCallbacks(tabStateMachine, canvas); }
/// <summary> /// Finds all the necessary UI elements that need to be updated/modified /// </summary> private void FindElements() { canvas = GameObject.Find("Canvas"); freeroamCameraWindow = AuxFunctions.FindObject(canvas, "FreeroamPanel"); spawnpointWindow = AuxFunctions.FindObject(canvas, "SpawnpointPanel"); multiplayerPanel = AuxFunctions.FindObject(canvas, "MultiplayerPanel"); driverStationPanel = AuxFunctions.FindObject(canvas, "DriverStationPanel"); changeRobotPanel = AuxFunctions.FindObject(canvas, "ChangeRobotPanel"); robotListPanel = AuxFunctions.FindObject(changeRobotPanel, "RobotListPanel"); changeFieldPanel = AuxFunctions.FindObject(canvas, "ChangeFieldPanel"); inputManagerPanel = AuxFunctions.FindObject(canvas, "InputManagerPanel"); checkSavePanel = AuxFunctions.FindObject(canvas, "CheckSavePanel"); unitConversionSwitch = AuxFunctions.FindObject(canvas, "UnitConversionSwitch"); hotKeyPanel = AuxFunctions.FindObject(canvas, "HotKeyPanel"); hotKeyButton = AuxFunctions.FindObject(canvas, "DisplayHotKeyButton"); orientWindow = AuxFunctions.FindObject(canvas, "OrientWindow"); resetDropdown = GameObject.Find("Reset Robot Dropdown"); exitPanel = AuxFunctions.FindObject(canvas, "ExitPanel"); loadingPanel = AuxFunctions.FindObject(canvas, "LoadingPanel"); analyticsPanel = AuxFunctions.FindObject(canvas, "AnalyticsPanel"); sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); robotCameraGUI = GameObject.Find("StateMachine").GetComponent <RobotCameraGUI>(); mixAndMatchPanel = AuxFunctions.FindObject(canvas, "MixAndMatchPanel"); toolbar = AuxFunctions.FindObject(canvas, "Toolbar"); changePanel = AuxFunctions.FindObject(canvas, "ChangePanel"); addPanel = AuxFunctions.FindObject(canvas, "AddPanel"); CheckControlPanel(); }
/// <summary> /// Called just after the robot is constructed. /// </summary> protected override void OnRobotSetup() { //Get the offset from the first node to the robot for new robot start position calculation //This line is CRITICAL to new reset position accuracy! DON'T DELETE IT! nodeToRobotOffset = gameObject.transform.GetChild(0).localPosition - robotStartPosition; //Initializes Driver Practice component dpmRobot = gameObject.AddComponent <DriverPracticeRobot>(); //Initializing robot cameras bool hasRobotCamera = false; //If you are getting an error referencing this line, it is likely that the Game Object "RobotCameraList" in Scene.unity does not have the RobotCameraManager script attached to it. robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); //Loop through robotCameraList and check if any existing camera should attach to this robot foreach (GameObject robotCamera in robotCameraManager.GetRobotCameraList()) { if (robotCamera.GetComponent <RobotCamera>().robot.Equals(this)) { //Recover the robot camera configurations robotCamera.GetComponent <RobotCamera>().RecoverConfiguration(); hasRobotCamera = true; } } //Add new cameras to the robot if there is none robot camera belong to the current robot (which means it is a new robot) if (!hasRobotCamera) { //Attached to the main frame and face the front robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0.5f, 0), new Vector3(0, 0, 0)); ////Attached to main frame and face the back robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0.5f, 0), new Vector3(0, 180, 0)); robotCameraManager.AddCamera(this, transform.GetChild(0).transform); } }
/// <summary> /// Called after Awake() when the script instance is enabled. /// Initializes variables then loads the field and robot as well as setting up replay features. /// </summary> public override void Start() { AppModel.ClearError(); //getting bullet physics information physicsWorld = BPhysicsWorld.Get(); ((DynamicsWorld)physicsWorld.world).SetInternalTickCallback(BPhysicsTickListener.Instance.PhysicsTick); lastFrameCount = physicsWorld.frameCount; //setting up raycast robot tick callback BPhysicsTickListener.Instance.OnTick -= BRobotManager.Instance.UpdateRaycastRobots; BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots; //starts a new instance of unity packet which receives packets from the driver station unityPacket.Start(); //If a replay has been selected, load the replay. Otherwise, load the field and robot. string selectedReplay = PlayerPrefs.GetString("simSelectedReplay"); if (string.IsNullOrEmpty(selectedReplay)) { Tracking = true; if (!LoadField(PlayerPrefs.GetString("simSelectedField"))) { AppModel.ErrorToMenu("Could not load field: " + PlayerPrefs.GetString("simSelectedField") + "\nHas it been moved or deleted?)"); return; } if (!LoadRobot(PlayerPrefs.GetString("simSelectedRobot"), RobotTypeManager.IsMixAndMatch)) { AppModel.ErrorToMenu("Could not load robot: " + PlayerPrefs.GetString("simSelectedRobot") + "\nHas it been moved or deleted?)"); return; } reset = FieldDataHandler.robotSpawn == new Vector3(99999, 99999, 99999); if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator) { Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "Load manipulator success" : "Load manipulator failed"); } } else { awaitingReplay = true; LoadReplay(selectedReplay); } //initializes the dynamic camera DynamicCameraObject = GameObject.Find("Main Camera"); dynamicCamera = DynamicCameraObject.AddComponent <DynamicCamera>(); DynamicCamera.ControlEnabled = true; sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManagerGUI = StateMachine.gameObject.GetComponent <SensorManagerGUI>(); simUI = StateMachine.SceneGlobal.GetComponent <SimUI>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric") ? true : false; StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject); StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(1).gameObject, false); StateMachine.Link <ReplayState>(Auxiliary.FindGameObject("ReplayUI")); StateMachine.Link <SaveReplayState>(Auxiliary.FindGameObject("SaveReplayUI")); StateMachine.Link <GamepieceSpawnState>(Auxiliary.FindGameObject("ResetGamepieceSpawnpointUI")); StateMachine.Link <DefineNodeState>(Auxiliary.FindGameObject("DefineNodeUI")); StateMachine.Link <GoalState>(Auxiliary.FindGameObject("GoalStateUI")); StateMachine.Link <SensorSpawnState>(Auxiliary.FindGameObject("ResetSensorSpawnpointUI")); StateMachine.Link <DefineSensorAttachmentState>(Auxiliary.FindGameObject("DefineSensorAttachmentUI")); string defaultDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"Autodesk\Synthesis\Emulator"); string directoryPath = ""; if (Directory.Exists(defaultDirectory)) { directoryPath = defaultDirectory; isEmulationDownloaded = true; } }
public DefineSensorAttachmentState(RobotCameraManager robotCameraManager) { camera = true; this.robotCameraManager = robotCameraManager; }
/// <summary> /// Called after Awake() when the script instance is enabled. /// Initializes variables then loads the field and robot as well as setting up replay features. /// </summary> public override void Start() { AppModel.ClearError(); //getting bullet physics information physicsWorld = BPhysicsWorld.Get(); ((DynamicsWorld)physicsWorld.world).SetInternalTickCallback(BPhysicsTickListener.Instance.PhysicsTick); lastFrameCount = physicsWorld.frameCount; //setting up raycast robot tick callback BPhysicsTickListener.Instance.OnTick -= BRobotManager.Instance.UpdateRaycastRobots; BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots; //setting up replay CollisionTracker = new CollisionTracker(this); //starts a new instance of unity packet which receives packets from the driver station unityPacket = new UnityPacket(); unityPacket.Start(); //loads all the controls Controls.Load(); //If a replay has been selected, load the replay. Otherwise, load the field and robot. string selectedReplay = PlayerPrefs.GetString("simSelectedReplay"); SpawnedRobots = new List <Robot>(); if (string.IsNullOrEmpty(selectedReplay)) { Tracking = true; if (!LoadField(PlayerPrefs.GetString("simSelectedField"))) { AppModel.ErrorToMenu("Could not load field: " + PlayerPrefs.GetString("simSelectedField") + "\nHas it been moved or deleted?)"); return; } if (!LoadRobot(PlayerPrefs.GetString("simSelectedRobot"), RobotTypeManager.IsMixAndMatch)) { AppModel.ErrorToMenu("Could not load robot: " + PlayerPrefs.GetString("simSelectedRobot") + "\nHas it been moved or deleted?)"); return; } if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator) { Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "Load manipulator success" : "Load manipulator failed"); } } else { awaitingReplay = true; LoadReplay(selectedReplay); } //initializes the dynamic camera DynamicCameraObject = GameObject.Find("Main Camera"); dynamicCamera = DynamicCameraObject.AddComponent <DynamicCamera>(); DynamicCamera.MovingEnabled = true; sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManagerGUI = GameObject.Find("StateMachine").GetComponent <SensorManagerGUI>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric") ? true : false; StateMachine.Instance.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject); StateMachine.Instance.Link <ReplayState>(Resources.FindObjectsOfTypeAll <GameObject>().First(x => x.name.Equals("ReplayUI"))); StateMachine.Instance.Link <SaveReplayState>(Resources.FindObjectsOfTypeAll <GameObject>().First(x => x.name.Equals("SaveReplayUI"))); }
/// <summary> /// Initializes physical robot based off of robot directory. /// </summary> /// <param name="directory">folder directory of robot</param> /// <returns></returns> public bool InitializeRobot(string directory, MainState source) { RobotIsMecanum = false; if (RobotIsMixAndMatch) { wheelPath = RobotTypeManager.WheelPath; wheelFriction = RobotTypeManager.WheelFriction; wheelLateralFriction = RobotTypeManager.WheelLateralFriction; wheelRadius = RobotTypeManager.WheelRadius; wheelMass = RobotTypeManager.WheelMass; RobotIsMecanum = RobotTypeManager.IsMecanum; } #region Robot Initialization RobotDirectory = directory; //Deletes all nodes if any exist, take the old node transforms out from the robot object int childCount = transform.childCount; for (int i = childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); //If this isn't done, the game object is destroyed but the parent-child transform relationship remains! child.parent = null; Destroy(child.gameObject); } //Detach and destroy all sensors on the original robot SensorManager sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManager.ResetSensorLists(); //Removes Driver Practice component if it exists if (dpmRobot != null) { Destroy(dpmRobot); } mainState = source; //stores the main state object transform.position = robotStartPosition; //Sets the position of the object to the set spawn point if (!File.Exists(directory + "\\skeleton.bxdj")) { return(false); } //Loads the node and skeleton data RigidNode_Base.NODE_FACTORY = delegate(Guid guid) { return(new RigidNode(guid)); }; List <RigidNode_Base> nodes = new List <RigidNode_Base>(); rootNode = BXDJSkeleton.ReadSkeleton(directory + "\\skeleton.bxdj"); rootNode.ListAllNodes(nodes); //Initializes the wheel variables int numWheels = nodes.Count(x => x.HasDriverMeta <WheelDriverMeta>() && x.GetDriverMeta <WheelDriverMeta>().type != WheelType.NOT_A_WHEEL); float collectiveMass = 0f; //Initializes the nodes and creates joints for the robot if (RobotIsMixAndMatch && !RobotIsMecanum) //If the user is in MaM and the robot they select is not mecanum, create the nodes and replace the wheel meshes to match those selected { //Load Node_0, the base of the robot RigidNode node = (RigidNode)nodes[0]; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName, true, wheelMass)) { Debug.Log("Robot not loaded!"); return(false); } node.CreateJoint(numWheels, RobotIsMixAndMatch); if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } //Get the wheel mesh data from the file they are stored in. They are stored as .bxda files. This may need to update if exporters/file types change. BXDAMesh mesh = new BXDAMesh(); mesh.ReadFromFile(wheelPath + "\\node_0.bxda"); List <Mesh> meshList = new List <Mesh>(); List <Material[]> materialList = new List <Material[]>(); RigidNode wheelNode = (RigidNode)BXDJSkeleton.ReadSkeleton(wheelPath + "\\skeleton.bxdj"); Material[] materials = new Material[0]; AuxFunctions.ReadMeshSet(mesh.meshes, delegate(int id, BXDAMesh.BXDASubMesh sub, Mesh meshu) { meshList.Add(meshu); materials = new Material[meshu.subMeshCount]; for (int i = 0; i < materials.Length; i++) { materials[i] = sub.surfaces[i].AsMaterial(true); } materialList.Add(materials); }, true); //Loads the other nodes from the original robot for (int i = 1; i < nodes.Count; i++) { node = (RigidNode)nodes[i]; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName, true, wheelMass)) { Debug.Log("Robot not loaded!"); return(false); } //If the node is a wheel, destroy the original wheel mesh and replace it with the wheels selected in MaM if (node.HasDriverMeta <WheelDriverMeta>()) { int chldCount = node.MainObject.transform.childCount; for (int j = 0; j < chldCount; j++) { Destroy(node.MainObject.transform.GetChild(j).gameObject); } int k = 0; Vector3?offset = null; foreach (Mesh meshObject in meshList) { GameObject meshObj = new GameObject(node.MainObject.name + "_mesh"); meshObj.transform.parent = node.MainObject.transform; meshObj.AddComponent <MeshFilter>().mesh = meshObject; if (!offset.HasValue) { offset = meshObject.bounds.center; } meshObj.transform.localPosition = -offset.Value; //Take out this line if you want some snazzy pink wheels meshObj.AddComponent <MeshRenderer>().materials = materialList[k]; k++; } node.MainObject.GetComponentInChildren <MeshRenderer>().materials = materials; } //Create the joints that interact with physics node.CreateJoint(numWheels, RobotIsMixAndMatch, wheelFriction, wheelLateralFriction); if (node.HasDriverMeta <WheelDriverMeta>()) { node.MainObject.GetComponent <BRaycastWheel>().Radius = wheelRadius; } if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } } } else //Initialize the robot as normal { //Initializes the nodes foreach (RigidNode_Base n in nodes) { RigidNode node = (RigidNode)n; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName)) { Debug.Log("Robot not loaded!"); return(false); } node.CreateJoint(numWheels, RobotIsMixAndMatch); if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } } } #endregion //Get the offset from the first node to the robot for new robot start position calculation //This line is CRITICAL to new reset position accuracy! DON'T DELETE IT! nodeToRobotOffset = gameObject.transform.GetChild(0).localPosition - robotStartPosition; foreach (BRaycastRobot r in GetComponentsInChildren <BRaycastRobot>()) { r.RaycastRobot.OverrideMass = collectiveMass; r.RaycastRobot.RootRigidBody = (RigidBody)((RigidNode)nodes[0]).MainObject.GetComponent <BRigidBody>().GetCollisionObject(); } RotateRobot(robotStartOrientation); RobotName = new DirectoryInfo(directory).Name; isInitialized = true; //Initializes Driver Practice component dpmRobot = gameObject.AddComponent <DriverPracticeRobot>(); dpmRobot.Initialize(directory); //Initializing robot cameras bool hasRobotCamera = false; //If you are getting an error referencing this line, it is likely that the Game Object "RobotCameraList" in Scene.unity does not have the RobotCameraManager script attached to it. robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); //Loop through robotCameraList and check if any existing camera should attach to this robot foreach (GameObject robotCamera in robotCameraManager.GetRobotCameraList()) { if (robotCamera.GetComponent <RobotCamera>().robot.Equals(this)) { //Recover the robot camera configurations robotCamera.GetComponent <RobotCamera>().RecoverConfiguration(); hasRobotCamera = true; } } //Add new cameras to the robot if there is none robot camera belong to the current robot (which means it is a new robot) if (!hasRobotCamera) { //Attached to the main frame and face the front robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0.5f, 0), new Vector3(0, 0, 0)); ////Attached to main frame and face the back robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0.5f, 0), new Vector3(0, 180, 0)); robotCameraManager.AddCamera(this, transform.GetChild(0).transform); } //Reads the offset position for the manipulator if (RobotIsMixAndMatch) { offset = Vector3.zero; try { using (TextReader reader = File.OpenText(directory + "\\position.txt")) { offset.x = float.Parse(reader.ReadLine()); offset.y = float.Parse(reader.ReadLine()); offset.z = float.Parse(reader.ReadLine()); } } catch { offset = Vector3.zero; } } return(true); }
/// <summary> /// Called after Awake() when the script instance is enabled. /// Initializes variables then loads the field and robot as well as setting up replay features. /// </summary> public override void Start() { AppModel.ClearError(); //getting bullet physics information physicsWorld = BPhysicsWorld.Get(); ((DynamicsWorld)physicsWorld.world).SetInternalTickCallback(BPhysicsTickListener.Instance.PhysicsTick); lastFrameCount = physicsWorld.frameCount; //setting up raycast robot tick callback BPhysicsTickListener.Instance.OnTick -= BRobotManager.Instance.UpdateRaycastRobots; BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots; //If a replay has been selected, load the replay. Otherwise, load the field and robot. string selectedReplay = PlayerPrefs.GetString("simSelectedReplay"); if (PlayerPrefs.GetString("simSelectedRobot", "").Equals("")) { AppModel.ErrorToMenu("ROBOT_SELECT|FIRST"); return; } if (string.IsNullOrEmpty(selectedReplay)) { Tracking = true; if (!LoadField(PlayerPrefs.GetString("simSelectedField"))) { //AppModel.ErrorToMenu("FIELD_SELECT|FIRST"); AppModel.ErrorToMenu("FIELD_SELECT|Could not load field: " + PlayerPrefs.GetString("simSelectedField") + "\nHas it been moved or deleted?)"); return; } else { MovePlane(); } bool result = false; try { result = LoadRobot(PlayerPrefs.GetString("simSelectedRobot"), false); } catch (Exception e) { MonoBehaviour.Destroy(GameObject.Find("Robot")); } if (!result) { AppModel.ErrorToMenu("ROBOT_SELECT|Could not find the selected robot"); return; } reset = FieldDataHandler.robotSpawn == new Vector3(99999, 99999, 99999); if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator) { Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "Load manipulator success" : "Load manipulator failed"); } } else { awaitingReplay = true; PlayerPrefs.SetString("simSelectedReplay", ""); LoadReplay(selectedReplay); } //initializes the dynamic camera DynamicCameraObject = GameObject.Find("Main Camera"); dynamicCamera = DynamicCameraObject.AddComponent <DynamicCamera>(); DynamicCamera.ControlEnabled = true; sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManagerGUI = StateMachine.gameObject.GetComponent <SensorManagerGUI>(); simUI = StateMachine.SceneGlobal.GetComponent <SimUI>(); robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric"); StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject); StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(1).gameObject, false); StateMachine.Link <ReplayState>(Auxiliary.FindGameObject("ReplayUI")); StateMachine.Link <SaveReplayState>(Auxiliary.FindGameObject("SaveReplayUI")); StateMachine.Link <GamepieceSpawnState>(Auxiliary.FindGameObject("ResetGamepieceSpawnpointUI")); StateMachine.Link <DefineNodeState>(Auxiliary.FindGameObject("DefineNodeUI")); StateMachine.Link <GoalState>(Auxiliary.FindGameObject("GoalStateUI")); StateMachine.Link <SensorSpawnState>(Auxiliary.FindGameObject("ResetSensorSpawnpointUI")); StateMachine.Link <DefineSensorAttachmentState>(Auxiliary.FindGameObject("DefineSensorAttachmentUI")); MediaManager.getInstance(); Controls.Load(); Controls.UpdateFieldControls(); Controls.Save(true); }
/// <summary> /// Initializes physical robot based off of robot directory. /// </summary> /// <param name="directory">folder directory of robot</param> /// <returns></returns> public bool InitializeRobot(string directory, MainState source) { #region Robot Initialization RobotDirectory = directory; //Deletes all nodes if any exist, take the old node transforms out from the robot object int childCount = transform.childCount; for (int i = childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); //If this isn't done, the game object is destroyed but the parent-child transform relationship remains! child.parent = null; Destroy(child.gameObject); } //Detach and destroy all sensors on the original robot SensorManager sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManager.ResetSensorLists(); //Removes Driver Practice component if it exists if (dpmRobot != null) { Destroy(dpmRobot); } mainState = source; //stores the main state object transform.position = robotStartPosition; //Sets the position of the object to the set spawn point if (!File.Exists(directory + "\\skeleton.bxdj")) { return(false); } //Loads the node and skeleton data RigidNode_Base.NODE_FACTORY = delegate(Guid guid) { return(new RigidNode(guid)); }; List <RigidNode_Base> nodes = new List <RigidNode_Base>(); rootNode = BXDJSkeleton.ReadSkeleton(directory + "\\skeleton.bxdj"); rootNode.ListAllNodes(nodes); //Initializes the wheel variables int numWheels = nodes.Count(x => x.HasDriverMeta <WheelDriverMeta>() && x.GetDriverMeta <WheelDriverMeta>().type != WheelType.NOT_A_WHEEL); float collectiveMass = 0f; int isMixAndMatch = PlayerPrefs.GetInt("mixAndMatch"); if (isMixAndMatch == 1 && !MixAndMatchMode.isMecanum) { //Load Node_0 RigidNode node = (RigidNode)nodes[0]; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName)) { Debug.Log("Robot not loaded!"); return(false); } node.CreateJoint(numWheels); if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } //Load the other nodes (wheels) string wheelDirectory = PlayerPrefs.GetString("simSelectedWheel"); BXDAMesh mesh = new BXDAMesh(); mesh.ReadFromFile(wheelDirectory + "\\node_0.bxda"); List <Mesh> meshList = new List <Mesh>(); List <Material[]> materialList = new List <Material[]>(); RigidNode wheelNode = (RigidNode)BXDJSkeleton.ReadSkeleton(wheelDirectory + "\\skeleton.bxdj"); Material[] materials = new Material[0]; AuxFunctions.ReadMeshSet(mesh.meshes, delegate(int id, BXDAMesh.BXDASubMesh sub, Mesh meshu) { meshList.Add(meshu); materials = new Material[meshu.subMeshCount]; for (int i = 0; i < materials.Length; i++) { materials[i] = sub.surfaces[i].AsMaterial(true); } materialList.Add(materials); //meshObject.GetComponent<MeshRenderer>().materials = materials; }, true); for (int i = 1; i < nodes.Count; i++) { node = (RigidNode)nodes[i]; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName)) { Debug.Log("Robot not loaded!"); return(false); } if (node.HasDriverMeta <WheelDriverMeta>()) { int chldCount = node.MainObject.transform.childCount; for (int j = 0; j < chldCount; j++) { Destroy(node.MainObject.transform.GetChild(j).gameObject); } int k = 0; foreach (Mesh meshObject in meshList) { Debug.Log("Mesh Object" + meshObject); GameObject meshObj = new GameObject(node.MainObject.name + "_mesh"); meshObj.transform.parent = node.MainObject.transform; meshObj.AddComponent <MeshFilter>().mesh = meshObject; meshObj.transform.localPosition = -meshObject.bounds.center; //Take out this line if you want some snazzy pink wheels meshObj.AddComponent <MeshRenderer>().materials = materialList[k]; k++; } node.MainObject.GetComponentInChildren <MeshRenderer>().materials = materials; } //node.MainObject.transform.GetChild(0).localPosition = -node.MainObject.GetComponentInChildren<MeshFilter>().mesh.bounds.center;// -node.MainObject.transform.localPosition; //Bounds b = node.MainObject.GetComponentInChildren<MeshFilter>().mesh.bounds; // Debug.Log(b.center); //b.center = node.MainObject.transform.position; //node.MainObject.GetComponentInChildren<MeshFilter>().mesh.bounds = b; node.CreateJoint(numWheels); if (node.HasDriverMeta <WheelDriverMeta>()) { float radius = PlayerPrefs.GetFloat("wheelRadius"); node.MainObject.GetComponent <BRaycastWheel>().Radius = radius; } if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } } } else { //Initializes the nodes foreach (RigidNode_Base n in nodes) { RigidNode node = (RigidNode)n; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName)) { Debug.Log("Robot not loaded!"); return(false); } node.CreateJoint(numWheels); if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } } } #endregion //Get the offset from the first node to the robot for new robot start position calculation //This line is CRITICAL to new reset position accuracy! DON'T DELETE IT! nodeToRobotOffset = gameObject.transform.GetChild(0).localPosition - robotStartPosition; foreach (BRaycastRobot r in GetComponentsInChildren <BRaycastRobot>()) { r.RaycastRobot.OverrideMass = collectiveMass; r.RaycastRobot.RootRigidBody = (RigidBody)((RigidNode)nodes[0]).MainObject.GetComponent <BRigidBody>().GetCollisionObject(); } RotateRobot(robotStartOrientation); RobotName = new DirectoryInfo(directory).Name; isInitialized = true; //Initializes Driver Practice component dpmRobot = gameObject.AddComponent <DriverPracticeRobot>(); dpmRobot.Initialize(directory); //Initializing robot cameras bool hasRobotCamera = false; //If you are getting an error referencing this line, it is likely that the Game Object "RobotCameraList" in Scene.unity does not have the RobotCameraManager script attached to it. robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); //Loop through robotCameraList and check if any existing camera should attach to this robot foreach (GameObject robotCamera in robotCameraManager.GetRobotCameraList()) { if (robotCamera.GetComponent <RobotCamera>().robot.Equals(this)) { //Recover the robot camera configurations robotCamera.GetComponent <RobotCamera>().RecoverConfiguration(); hasRobotCamera = true; } } //Add new cameras to the robot if there is none robot camera belong to the current robot (which means it is a new robot) if (!hasRobotCamera) { //Attached to the main frame and face the front robotCameraManager.AddCamera(this, transform.GetChild(0).transform); //Attached to the first node and face the front if (transform.childCount > 1) { robotCameraManager.AddCamera(this, transform.GetChild(1).transform); } ////Attached to main frame and face the back robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0, 0), new Vector3(0, 180, 0)); } return(true); }
/// <summary> /// Initializes physical robot based off of robot directory. /// </summary> /// <param name="directory">folder directory of robot</param> /// <returns></returns> public bool InitializeRobot(string directory, MainState source) { //Deletes all nodes if any exist, take the old node transforms out from the robot object int childCount = transform.childCount; for (int i = childCount - 1; i >= 0; i--) { Transform child = transform.GetChild(i); //If not do this the game object is destroyed but the parent-child transform relationship remains! child.parent = null; Destroy(child.gameObject); } SensorManager sensorManager = GameObject.Find("SensorManager").GetComponent <SensorManager>(); sensorManager.ResetSensorLists(); mainState = source; transform.position = robotStartPosition; RigidNode_Base.NODE_FACTORY = delegate(Guid guid) { return(new RigidNode(guid)); }; List <RigidNode_Base> nodes = new List <RigidNode_Base>(); //Read .robot instead. Maybe need a RobotSkeleton class rootNode = BXDJSkeleton.ReadSkeleton(directory + "\\skeleton.bxdj"); rootNode.ListAllNodes(nodes); int numWheels = nodes.Count(x => x.HasDriverMeta <WheelDriverMeta>() && x.GetDriverMeta <WheelDriverMeta>().type != WheelType.NOT_A_WHEEL); float collectiveMass = 0f; foreach (RigidNode_Base n in nodes) { RigidNode node = (RigidNode)n; node.CreateTransform(transform); if (!node.CreateMesh(directory + "\\" + node.ModelFileName)) { Debug.Log("Robot not loaded!"); return(false); } node.CreateJoint(numWheels); if (node.PhysicalProperties != null) { collectiveMass += node.PhysicalProperties.mass; } if (node.MainObject.GetComponent <BRigidBody>() != null) { node.MainObject.AddComponent <Tracker>().Trace = true; } } foreach (BRaycastRobot r in GetComponentsInChildren <BRaycastRobot>()) { r.RaycastRobot.EffectiveMass = collectiveMass; } RotateRobot(robotStartOrientation); RobotName = new DirectoryInfo(directory).Name; isInitialized = true; bool hasRobotCamera = false; robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>(); foreach (GameObject robotCamera in robotCameraManager.GetRobotCameraList()) { if (robotCamera.GetComponent <RobotCamera>().robot.Equals(this)) { robotCamera.GetComponent <RobotCamera>().RecoverConfiguration(); hasRobotCamera = true; Debug.Log(hasRobotCamera); } } if (!hasRobotCamera) { //Attached to the main frame and face the front robotCameraManager.AddCamera(this, transform.GetChild(0).transform); //Attached to the first node and face the front if (transform.childCount > 1) { robotCameraManager.AddCamera(this, transform.GetChild(1).transform); } ////Attached to main frame and face the back robotCameraManager.AddCamera(this, transform.GetChild(0).transform, new Vector3(0, 0, 0), new Vector3(0, 180, 0)); } //sensorManager.AddBeamBreaker(transform.GetChild(0).gameObject, new Vector3(0, 0, 1), new Vector3(0, 90, 0), 1); //sensorManager.AddUltrasonicSensor(transform.GetChild(0).gameObject, new Vector3(0, 0, 0), new Vector3(0, 0, 0)); //sensorManager.AddGyro(transform.GetChild(0).gameObject, new Vector3(0, 0, 0), new Vector3(0, 0, 0)); return(true); }