/// <summary> /// Allows the user to select a robot node with their mouse and change the intake/release node /// </summary> /// <param name="index">configuring index</param> public void SetMechanism(int index) { //Casts a ray from the camera in the direction the mouse is in and returns the closest object hit Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); BulletSharp.Math.Vector3 start = ray.origin.ToBullet(); BulletSharp.Math.Vector3 end = ray.GetPoint(200).ToBullet(); //Creates a callback result that will be updated if we do a ray test with it ClosestRayResultCallback rayResult = new ClosestRayResultCallback(ref start, ref end); //Retrieves the bullet physics world and does a ray test with the given coordinates and updates the callback object BPhysicsWorld world = BPhysicsWorld.Get(); world.world.RayTest(start, end, rayResult); //If there is a collision object and it is dynamic and not a robot part, change the gamepiece to that if (rayResult.CollisionObject != null) { GameObject collisionObject = (rayResult.CollisionObject.UserObject as BRigidBody).gameObject; if (rayResult.CollisionObject.CollisionFlags == BulletSharp.CollisionFlags.StaticObject) { UserMessageManager.Dispatch("Please click on a robot part", 3); } else if (collisionObject == null) { Debug.Log("DPM: Game object not found"); } else if (collisionObject.transform.parent == transform) { if (definingIntake) { intakeNode[index] = collisionObject; SetInteractor(intakeNode[index], index); UserMessageManager.Dispatch(collisionObject.name + " has been selected as intake node", 5); definingIntake = false; } else { releaseNode[index] = collisionObject; SetInteractor(releaseNode[index], index); UserMessageManager.Dispatch(collisionObject.name + " has been selected as release node", 5); definingRelease = false; } RevertNodeColors(hoveredNode, hoveredColors); } else { UserMessageManager.Dispatch("A gamepiece is NOT a robot part!", 3); } } else { } }
public override void Update() { if (loadingPanel.activeSelf) { Text t = loadingPanel.transform.Find("Text").GetComponent <Text>(); if (!EmulatorManager.IsVMConnected()) { uploadFinished = true; uploadSuccess = false; } if (uploadFinished) { if (!uploadSuccess) { UserMessageManager.Dispatch("Failed to upload new user program", EmulationWarnings.WARNING_DURATION); } t.text = "Loading..."; loadingPanel.SetActive(false); uploadFinished = false; } else { if (Time.unscaledTime >= lastAdditionalDot + 0.75) { dotCount = (dotCount + 1) % 4; t.text = "Loading"; for (int i = 0; i < dotCount; i++) { t.text += "."; } lastAdditionalDot = Time.unscaledTime; } } } }
/// <summary> /// Starts the main simulator when the start button is pressed. /// </summary> public void OnStartButtonClicked() { string selectedField = PlayerPrefs.GetString("simSelectedField"); string selectedRobot = PlayerPrefs.GetString("simSelectedRobot"); if (Directory.Exists(selectedField) && Directory.Exists(selectedRobot)) { AnalyticsManager.GlobalInstance.LogTimingAsync(AnalyticsLedger.TimingCatagory.Main, AnalyticsLedger.TimingVarible.Customizing, AnalyticsLedger.TimingLabel.MainSimMenu); AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.MainSimulator, AnalyticsLedger.EventAction.StartSim, "", AnalyticsLedger.getMilliseconds().ToString()); splashScreen.SetActive(true); PlayerPrefs.SetString("simSelectedReplay", string.Empty); SceneManager.LoadScene("Scene"); // Start timer to later log event when user reloads field AnalyticsManager.GlobalInstance.StartTime(AnalyticsLedger.TimingLabel.MainSimulator, AnalyticsLedger.TimingVarible.Starting); RobotTypeManager.SetProperties(false); } else { UserMessageManager.Dispatch("No Robot/Field Selected!", 2); } }
/// <summary> /// Runs every frame to update the GUI elements. /// </summary> void OnGUI() { switch (currentTab) { case Tab.FieldDir: if (customfieldon && !fieldBrowser.Active) { currentTab = Tab.Sim; homeTab.SetActive(false); optionsTab.SetActive(false); simTab.SetActive(true); customfieldon = false; } break; case Tab.RobotDir: if (customroboton && !robotBrowser.Active) { currentTab = Tab.Sim; homeTab.SetActive(false); optionsTab.SetActive(false); simTab.SetActive(true); customroboton = false; } break; } InitFieldBrowser(); InitRobotBrowser(); UserMessageManager.Render(); UserMessageManager.scale = canvas.scaleFactor; }
/// <summary> /// Called when the "Select Field" button is clicked within the field selection panel /// </summary> public void SelectSimField() { GameObject fieldList = GameObject.Find("SimLoadFieldList"); string entry = (fieldList.GetComponent <SelectFieldScrollable>().selectedEntry); if (entry != null) { simSelectedFieldName = fieldList.GetComponent <SelectFieldScrollable>().selectedEntry; simSelectedField = fieldDirectory + "\\" + simSelectedFieldName + "\\"; if (isMixAndMatch) //Starts the MixAndMatch scene { PlayerPrefs.SetString("simSelectedField", simSelectedField); fieldList.SetActive(false); splashScreen.SetActive(true); mixAndMatchModeScript.GetComponent <MixAndMatchMode>().StartSwapSim(); } else { SwitchSimDefault(); } } else { UserMessageManager.Dispatch("No Field Selected!", 2); } }
void Update() { if (mainNode == null) { mainNode = GameObject.Find("node_0.bxda"); resetRobot(); } //Debug.Log(filePath); if (reloadRobotInFrames >= 0 && reloadRobotInFrames-- == 0) { reloadRobotInFrames = -1; TryLoadRobot(); } if (reloadFieldInFrames >= 0 && reloadFieldInFrames-- == 0) { reloadFieldInFrames = -1; TryLoadField(); if (fieldLoaded) { filePath = PlayerPrefs.GetString("simSelectedRobot"); TryLoadRobot(); showStatWindow = true; } else { UserMessageManager.Dispatch("Incompatible Mesh!", 10f); Application.LoadLevel(0); } } // Reset Robot if (Input.GetKeyDown(Controls.ControlKey[(int)Controls.Control.ResetRobot])) { gui.DoAction("Reset Robot"); } if (Input.GetKeyDown(Controls.ControlKey[(int)Controls.Control.RobotOrient])) { if (!oWindow.Active) { gui.EscPressed(); oWindow.Active = true; } else { gui.EscPressed(); oWindow.Active = false; } } // Show/Hide physics window if (Input.GetKeyDown(Controls.ControlKey[(int)Controls.Control.Stats])) { showStatWindow = !showStatWindow; } }
/// <summary> /// Saves the current selected robot and pops the current <see cref="State"/> when /// the select robot button is pressed. /// </summary> public void OnSelectRobotButtonClicked() { GameObject robotList = GameObject.Find("SimLoadRobotList"); string entry = (robotList.GetComponent <SelectScrollable>().selectedEntry); if (entry != null) { string simSelectedRobotName = robotList.GetComponent <SelectScrollable>().selectedEntry; PlayerPrefs.SetString("simSelectedRobot", robotDirectory + "\\" + simSelectedRobotName + "\\"); PlayerPrefs.SetString("simSelectedRobotName", simSelectedRobotName); if (nextState == null) { StateMachine.PopState(); } else { StateMachine.PushState(nextState); } } else { UserMessageManager.Dispatch("No Robot Selected!", 2); } }
// Update is called once per frame public override void Update() { if (spawnIndicator != null) { if (UnityEngine.Input.GetKey(KeyCode.A)) { spawnIndicator.transform.position += UnityEngine.Vector3.forward * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.D)) { spawnIndicator.transform.position += UnityEngine.Vector3.back * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.W)) { spawnIndicator.transform.position += UnityEngine.Vector3.right * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.S)) { spawnIndicator.transform.position += UnityEngine.Vector3.left * 0.1f; } if (UnityEngine.Input.GetKeyDown(KeyCode.Return)) { UserMessageManager.Dispatch("New gamepiece spawn location has been set!", 3f); FieldDataHandler.gamepieces[gamepieceIndex].spawnpoint = spawnIndicator.transform.position; FieldDataHandler.WriteField(); ReturnToMainState(); } if (UnityEngine.Input.GetKeyDown(KeyCode.Escape)) { ReturnToMainState(); } } }
/// <summary> /// Returns to the lobby if the back button is pressed on the host instance. /// </summary> public void OnBackButtonPressed() { if (Host) MatchManager.Instance.CancelSync(); else UserMessageManager.Dispatch("Only the host can cancel synchronization!", 8f); }
public void InitFieldBrowser() { if (fieldBrowser == null) { fieldBrowser = new FileBrowser("Choose Field Directory", true); fieldBrowser.Active = true; fieldBrowser.OnComplete += (object obj) => { fieldBrowser.Active = true; string fileLocation = (string)obj; // If dir was selected... DirectoryInfo directory = new DirectoryInfo(fileLocation); if (directory != null && directory.Exists) { Debug.Log(directory); fieldDirectory = (directory.FullName); SwitchState(Menu.LoadField); customfieldon = false; PlayerPrefs.SetString("FieldDirectory", fieldDirectory); PlayerPrefs.Save(); UpdateFieldDirectory(); } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } }; } if (customfieldon) { fieldBrowser.Render(); } }
/// <summary> /// When the user enters the name for a preset, creates a MaMPreset object with the name and selected parts and adds it to the list. /// Also creates a GameObject clone of the preset prefab and adds it to the presetClones list. /// </summary> public void SetPresetName() { String name = ""; if (inputField.GetComponent <InputField>().text.Length > 0) { name = inputField.GetComponent <InputField>().text; } else { UserMessageManager.Dispatch("Please enter a name", 5); ToggleSetPresetPanel(); return; } foreach (MaMPreset preset in XMLManager.ins.itemDB.xmlList) { if (name == preset.GetName()) { UserMessageManager.Dispatch("Please choose a new preset name", 5); ToggleSetPresetPanel(); return; } } XMLManager.ins.itemDB.xmlList.Add(new MaMPreset(SelectedWheel, selectedDriveBase, selectedManipulator, name)); XMLManager.ins.SaveItems(); int clonePosition = (PresetClones.Count < 3) ? PresetClones.Count : 0; GameObject clone = presetsPanel.GetComponent <MaMPresetMono>().CreateClone(XMLManager.ins.itemDB.xmlList[PresetClones.Count], clonePosition); clone.GetComponent <Text>().text = XMLManager.ins.itemDB.xmlList[PresetClones.Count].GetName(); SetPresetFontSize(clone); PresetClones.Add(clone); if (PresetClones.Count > 3) { clone.SetActive(false); presetRightScroll.SetActive(true); } //Creates a listener for OnClick int value = PresetClones.Count - 1; Button buttonCtrl = clone.GetComponent <Button>(); buttonCtrl.onClick.AddListener(() => SelectPresets(value)); Text txt = infoText.GetComponent <Text>(); txt.text = XMLManager.ins.itemDB.xmlList[PresetClones.Count - 1].GetName(); if (SimUI.changeAnalytics) //for analytics tracking { Analytics.CustomEvent("Created Mix and Match Preset", new Dictionary <string, object> { }); } inputField.GetComponent <InputField>().text = ""; }
/// <summary> /// Saves the current selected robot and pops the current <see cref="State"/> when /// the select robot button is pressed. /// </summary> public void OnSelectRobotButtonClicked() { GameObject robotList = GameObject.Find("SimLoadRobotList"); string entry = (robotList.GetComponent <SelectScrollable>().selectedEntry); if (entry != null) { string simSelectedRobotName = robotList.GetComponent <SelectScrollable>().selectedEntry; robotDirectory = PlayerPrefs.GetString("RobotDirectory"); PlayerPrefs.SetString("simSelectedRobot", robotDirectory + Path.DirectorySeparatorChar + simSelectedRobotName + Path.DirectorySeparatorChar); PlayerPrefs.SetString("simSelectedRobotName", simSelectedRobotName); if (nextState == null) { StateMachine.PopState(); } else { StateMachine.PushState(nextState); } } else { UserMessageManager.Dispatch("No Robot Selected!", 2); } Auxiliary.FindGameObject("LoadSplash").SetActive(true); Auxiliary.FindGameObject("SimLoadRobot").SetActive(false); // StateMachine.ChangeState(new ErrorScreenState()); SceneManager.LoadScene("Scene"); }
public void ChangeField() { GameObject panel = GameObject.Find("FieldListPanel"); string directory = PlayerPrefs.GetString("FieldDirectory") + "\\" + panel.GetComponent <ChangeFieldScrollable>().selectedEntry; if (Directory.Exists(directory)) { panel.SetActive(false); changeFieldPanel.SetActive(false); loadingPanel.SetActive(true); PlayerPrefs.SetString("simSelectedReplay", string.Empty); PlayerPrefs.SetString("simSelectedField", directory); PlayerPrefs.SetString("simSelectedFieldName", panel.GetComponent <ChangeFieldScrollable>().selectedEntry); PlayerPrefs.Save(); if (changeAnalytics) //for analytics tracking { Analytics.CustomEvent("Changed Field", new Dictionary <string, object> { }); SceneManager.LoadScene("Scene"); } else { UserMessageManager.Dispatch("Field directory not found!", 5); } } }
void Update() { if (selectedEntry != null) { if (Input.GetKeyDown(KeyCode.Escape)) { selectedEntry = null; return; } foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode))) { if (Input.GetKeyDown(vKey)) { Controls.SetControl(inputNames.IndexOf(selectedEntry), vKey); Controls.SaveControls(); selectedEntry = null; if (Controls.CheckConflict()) { UserMessageManager.Dispatch("There is a conflict in the input settings!", 5); } UpdateControlList(); } } } }
public void InitRobotBrowser() { if (robotBrowser == null) { robotBrowser = new FileBrowser("Choose Robot Directory", robotDirectory, true); robotBrowser.Active = true; robotBrowser.OnComplete += (object obj) => { robotBrowser.Active = true; string fileLocation = (string)obj; // If dir was selected... DirectoryInfo directory = new DirectoryInfo(fileLocation); if (directory != null && directory.Exists) { robotDirectory = (directory.FullName); currentTab = Tab.Sim; SwitchTabSim(); customroboton = false; PlayerPrefs.SetString("RobotDirectory", robotDirectory); PlayerPrefs.Save(); } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } }; } if (customroboton) { robotBrowser.Render(); } }
/// <summary> /// Set the node where the camera will be attached to /// </summary> public void SetNode() { //Casts a ray from the camera in the direction the mouse is in and returns the closest object hit Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); BulletSharp.Math.Vector3 start = ray.origin.ToBullet(); BulletSharp.Math.Vector3 end = ray.GetPoint(200).ToBullet(); //Creates a callback result that will be updated if we do a ray test with it ClosestRayResultCallback rayResult = new ClosestRayResultCallback(ref start, ref end); //Retrieves the bullet physics world and does a ray test with the given coordinates and updates the callback object BPhysicsWorld world = BPhysicsWorld.Get(); world.world.RayTest(start, end, rayResult); Debug.Log("Selected:" + rayResult.CollisionObject); //If there is a collision object and it is a robot part, set that to be new attachment point if (rayResult.CollisionObject != null) { GameObject selectedObject = ((BRigidBody)rayResult.CollisionObject.UserObject).gameObject; if (selectedObject.transform.parent != null && selectedObject.transform.parent.name == "Robot") { string name = selectedObject.name; SelectedNode = selectedObject; UserMessageManager.Dispatch(name + " has been selected as the node for camera attachment", 5); } else { UserMessageManager.Dispatch("Please select a robot node", 3); } } }
private void UpdateGamepieceSpawn() { int index = settingSpawn - 1; if (spawnIndicator != null) { ((DynamicCamera.SateliteState)Camera.main.transform.GetComponent <DynamicCamera>().cameraState).target = spawnIndicator; if (Input.GetKey(KeyCode.LeftArrow)) { spawnIndicator.transform.position += UnityEngine.Vector3.forward * 0.1f; } if (Input.GetKey(KeyCode.RightArrow)) { spawnIndicator.transform.position += UnityEngine.Vector3.back * 0.1f; } if (Input.GetKey(KeyCode.UpArrow)) { spawnIndicator.transform.position += UnityEngine.Vector3.right * 0.1f; } if (Input.GetKey(KeyCode.DownArrow)) { spawnIndicator.transform.position += UnityEngine.Vector3.left * 0.1f; } if (Input.GetKeyDown(KeyCode.Return)) { UserMessageManager.Dispatch("New gamepiece spawn location has been set!", 3f); gamepieceSpawn[index] = spawnIndicator.transform.position; FinishGamepieceSpawn(); } } }
/// <summary> /// Spawns a new gamepiece at its defined spawn location, or at the field's origin if one hasn't been defined. /// </summary> /// <param name="index">0 if primary gamepiece, 1 if secondary gamepiece</param> public void SpawnGamepiece(int index) { if (gamepieceNames[index] != null) { try //In case the game piece somehow doens't exist in the scene { GameObject gameobject = Instantiate(AuxFunctions.FindObject(gamepieceNames[index]).GetComponentInParent <BRigidBody>().gameObject, gamepieceSpawn[index], UnityEngine.Quaternion.identity); gameobject.name = gamepieceNames[index] + "(Clone)"; gameobject.GetComponent <BRigidBody>().collisionFlags = BulletSharp.CollisionFlags.None; gameobject.GetComponent <BRigidBody>().velocity = UnityEngine.Vector3.zero; gameobject.tag = "Gamepiece_" + ((index == 0) ? "Primary" : "Secondary"); // Tagging so we can use it with the scoring area gameobject.GetComponent <GamePieceRememberSpawnParams>().PieceType = index; // allow us to easily reinstantiate from other scripts // gameobject.GetComponent<SphereCollider>().isTrigger = true; // gameobject.transform.GetChild(0).gameObject.AddComponent<MeshCollider>(); // gameobject.transform.GetChild(0).gameObject.GetComponent<MeshCollider>().isTrigger = true; // gameobject.transform.GetChild(0).gameObject.GetComponent<MeshCollider>().inflateMesh = true; // gameobject.transform.GetChild(0).gameObject.GetComponent<MeshCollider>().convex = true; // gameobject.transform.GetChild(0).gameObject.GetComponent<MeshCollider>().sharedMesh = // gameobject.transform.GetChild(0).gameObject.GetComponent<MeshFilter>().mesh; spawnedGamepieces[index].Add(gameobject); } catch { UserMessageManager.Dispatch("Gamepiece not found!", 5); } } else { UserMessageManager.Dispatch("You must define the gamepiece first!", 5); } }
/// <summary> /// Adds a new robot to the field based on user selection in the popup robot list window /// </summary> public void AddRobot() { if (SimUI.changeAnalytics) { Analytics.CustomEvent("Added Robot", new Dictionary <string, object> { }); } GameObject panel = GameObject.Find("RobotListPanel"); string directory = PlayerPrefs.GetString("RobotDirectory") + "\\" + panel.GetComponent <ChangeRobotScrollable>().selectedEntry; if (Directory.Exists(directory)) { PlayerPrefs.SetString("simSelectedReplay", string.Empty); mainState.LoadRobot(directory, false); } else { UserMessageManager.Dispatch("Robot directory not found!", 5); } ToggleAddRobotWindow(); UpdateUI(); PlayerPrefs.SetInt("hasManipulator", 0); //0 for false, 1 for true }
/// <summary> /// Activate the state of choosing anchor node for new sensors to attach /// </summary> public void ToggleAddSensor() { isAddingSensor = !isAddingSensor; sensorManager.SelectingNode = isAddingSensor; selectExistingButton.SetActive(!isAddingSensor); cancelOptionButton.SetActive(isAddingSensor); cancelOptionButton.transform.position = selectExistingButton.transform.position; sensorOptionToolTip.SetActive(isAddingSensor); if (isAddingSensor) { addSensorButton.GetComponentInChildren <Text>().text = "Confirm"; sensorOptionToolTip.GetComponentInChildren <Text>().text = "Select the robot node to which the new sensor will attach and Confirm"; UserMessageManager.Dispatch("Please select a robot node for sensor attachment", 3); } else { addSensorButton.GetComponentInChildren <Text>().text = "Add New Sensor"; //Turn off selectingNode state //Update the node selected to selectedNode SyncNodeSelection(); //Activate sensor type panel if a valid node is selected if (selectedNode != null) { sensorTypePanel.SetActive(true); sensorOptionPanel.SetActive(false); CancelOptionSelection(); } //Stay at sensor option panel else { UserMessageManager.Dispatch("No node selected!", 3f); } } }
public void ChangeRobot() { GameObject panel = GameObject.Find("RobotListPanel"); string directory = PlayerPrefs.GetString("RobotDirectory") + "\\" + panel.GetComponent <ChangeRobotScrollable>().selectedEntry; if (Directory.Exists(directory)) { panel.SetActive(false); changeRobotPanel.SetActive(false); PlayerPrefs.SetString("simSelectedReplay", string.Empty); PlayerPrefs.SetString("simSelectedRobot", directory); PlayerPrefs.SetString("simSelectedRobotName", panel.GetComponent <ChangeRobotScrollable>().selectedEntry); PlayerPrefs.SetInt("hasManipulator", 0); //0 is false, 1 is true PlayerPrefs.Save(); if (changeAnalytics) //for analytics tracking { Analytics.CustomEvent("Changed Robot", new Dictionary <string, object> { }); } robotCameraManager.DetachCamerasFromRobot(main.ActiveRobot); sensorManager.RemoveSensorsFromRobot(main.ActiveRobot); main.ChangeRobot(directory, false); } else { UserMessageManager.Dispatch("Robot directory not found!", 5); } }
/// <summary> /// When user click left mouse, use raycast to select a node for attachment, and highlight accordingly /// </summary> public void SetNode() { //Casts a ray from the camera in the direction the mouse is in and returns the closest object hit Ray ray = UnityEngine.Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition); BulletSharp.Math.Vector3 start = ray.origin.ToBullet(); BulletSharp.Math.Vector3 end = ray.GetPoint(200).ToBullet(); //Creates a callback result that will be updated if we do a ray test with it ClosestRayResultCallback rayResult = new ClosestRayResultCallback(ref start, ref end); //Retrieves the bullet physics world and does a ray test with the given coordinates and updates the callback object BPhysicsWorld world = BPhysicsWorld.Get(); world.world.RayTest(start, end, rayResult); //If there is a collision object and it is a robot part, set that to be new attachment point if (rayResult.CollisionObject != null) { GameObject selectedObject = ((BRigidBody)rayResult.CollisionObject.UserObject).gameObject; if (selectedObject.transform.parent != null && selectedObject.transform.parent.name == "Robot") { if (lastNode != null && !selectedObject.Equals(lastNode)) { RevertNodeColors(lastNode, hoveredColors); lastNode = null; } else { ChangeNodeColors(selectedObject, hoverColor, hoveredColors); lastNode = selectedObject; } if (UnityEngine.Input.GetMouseButtonDown(0)) { string name = selectedObject.name; RevertNodeColors(lastNode, hoveredColors); RevertNodeColors(SelectedNode, selectedColors); SelectedNode = selectedObject; ChangeNodeColors(SelectedNode, selectedColor, selectedColors); UserMessageManager.Dispatch(name + " has been selected as the node for sensor attachment", 5); } } else { if (lastNode != null) { RevertNodeColors(lastNode, hoveredColors); lastNode = null; } if (UnityEngine.Input.GetMouseButtonDown(0)) { UserMessageManager.Dispatch("Please select a robot node!", 3); } } } }
public override void End() { menuUI.EndOtherProcesses(); if (!Synthesis.Input.Controls.HasBeenSaved()) { Synthesis.Input.Controls.Load(); UserMessageManager.Dispatch("Control changes discarded", 4); } }
// Update is called once per frame public override void Update() { if (goalIndicator != null) { if (move) { if (UnityEngine.Input.GetKey(KeyCode.A)) { goalIndicator.transform.position += UnityEngine.Vector3.forward * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.D)) { goalIndicator.transform.position += UnityEngine.Vector3.back * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.W)) { goalIndicator.transform.position += UnityEngine.Vector3.right * 0.1f; } if (UnityEngine.Input.GetKey(KeyCode.S)) { goalIndicator.transform.position += UnityEngine.Vector3.left * 0.1f; } } if (UnityEngine.Input.GetKeyDown(KeyCode.Return)) { UserMessageManager.Dispatch("New goal location has been set!", 3f); if (color.Equals("Red")) { gm.redGoals[gamepieceIndex][goalIndex].GetComponent <BRigidBody>().SetPosition(goalIndicator.transform.position); gm.redGoals[gamepieceIndex][goalIndex].GetComponent <BBoxShape>().LocalScaling = goalIndicator.transform.localScale; gm.redGoals[gamepieceIndex][goalIndex].GetComponent <Goal>().position = goalIndicator.transform.position; gm.redGoals[gamepieceIndex][goalIndex].GetComponent <Goal>().scale = goalIndicator.transform.localScale; } else { gm.blueGoals[gamepieceIndex][goalIndex].GetComponent <BRigidBody>().SetPosition(goalIndicator.transform.position); gm.blueGoals[gamepieceIndex][goalIndex].GetComponent <BBoxShape>().LocalScaling = goalIndicator.transform.localScale; gm.blueGoals[gamepieceIndex][goalIndex].GetComponent <Goal>().position = goalIndicator.transform.position; gm.blueGoals[gamepieceIndex][goalIndex].GetComponent <Goal>().scale = goalIndicator.transform.localScale; } gm.WriteGoals(); ReturnToMainState(); return; } if (UnityEngine.Input.GetKeyDown(KeyCode.Escape)) { ReturnToMainState(); } } }
private void RpcPopState(string msg) { PlayerIdentity.LocalInstance.CmdSetReady(false); uiStateMachine.PopState(); if (!msg.Equals(string.Empty)) { UserMessageManager.Dispatch(msg, 8f); } }
/// <summary> /// Saves the replay from the provided file name. /// </summary> public void Save() { if (string.IsNullOrEmpty(replayNameText.text) || replayNameText.text.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { UserMessageManager.Dispatch("Please enter a valid replay name!", 5f); return; } ReplayExporter.Write(replayNameText.text, fieldPath, robotPath, trackers, contacts); StateMachine.Instance.PopState(); }
public void EnterReplayState() { if (!activeRobot.IsResetting) { CollisionTracker.Synchronize(lastFrameCount); StateMachine.Instance.PushState(new ReplayState(fieldPath, robotPath, CollisionTracker.ContactPoints, Trackers)); } else { UserMessageManager.Dispatch("Please finish resetting before entering replay mode!", 5f); } }
/// <summary> /// Starts the replay state. /// </summary> public void EnterReplayState() { if (!ActiveRobot.IsResetting) { CollisionTracker.ContactPoints.Add(null); StateMachine.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints)); } else { UserMessageManager.Dispatch("Please finish resetting before entering replay mode!", 5f); } }
/// <summary> /// When user click left mouse, use raycast to select a sensor for configuration, and highlight accordingly /// </summary> public void SetSensor() { RaycastHit hitInfo = new RaycastHit(); Ray ray = UnityEngine.Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition); Physics.Raycast(ray, out hitInfo); if (hitInfo.transform != null && hitInfo.transform.gameObject.tag == "Sensor") { GameObject selectedObject; //If the sensor is a beam breaker, select the parent object instead if (hitInfo.transform.gameObject.transform.parent.gameObject.GetComponent <BeamBreaker>() != null) { selectedObject = hitInfo.transform.gameObject.transform.parent.gameObject; } else { selectedObject = hitInfo.transform.gameObject; } if (lastNode != null && !selectedObject.Equals(lastNode)) { RevertNodeColors(lastNode, hoveredColors); lastNode = null; } else { ChangeNodeColors(selectedObject, hoverColor, hoveredColors); lastNode = selectedObject; } if (UnityEngine.Input.GetMouseButtonDown(0)) { RevertNodeColors(lastNode, hoveredColors); RevertNodeColors(SelectedSensor, selectedColors); SelectedSensor = selectedObject; ChangeNodeColors(SelectedSensor, selectedColor, selectedColors); UserMessageManager.Dispatch(SelectedSensor.name + " has been selected as the current sensor", 5); } } else { if (lastNode != null) { RevertNodeColors(lastNode, hoveredColors); lastNode = null; } if (UnityEngine.Input.GetMouseButtonDown(0)) { UserMessageManager.Dispatch("Please select a sensor!", 3); } } }
//Selects the robot, records the filename, and switches to the main menu. public void SelectRobotButtonClicked() { if (robots.Count > 0) { selectedRobot = (robotDirectory + "\\" + robots[robotindex] + "\\"); selectedRobotName = "Robot: " + currenttext; SwitchState(Menu.Main); } else { UserMessageManager.Dispatch("No robot in directory!", 2); } }