/// <summary> /// Opens windows to orient the robot /// </summary> public void ShowOrient() { List <string> titles = new List <string> (); titles.Add("Left"); titles.Add("Right"); titles.Add("Forward"); titles.Add("Back"); titles.Add("Save Orientation"); titles.Add("Close"); titles.Add("Default"); List <Rect> rects = new List <Rect> (); rects.Add(new Rect(40, 200, 105, 35)); rects.Add(new Rect(245, 200, 105, 35)); rects.Add(new Rect(147, 155, 105, 35)); rects.Add(new Rect(147, 245, 105, 35)); rects.Add(new Rect(110, 95, 190, 35)); rects.Add(new Rect(270, 50, 90, 35)); rects.Add(new Rect(50, 50, 90, 35)); oWindow = new TextWindow("Orient Robot", new Rect((Screen.width / 2) - 150, (Screen.height / 2) - 125, 400, 300), new string[0], new Rect[0], titles.ToArray(), rects.ToArray()); //The directional buttons lift the robot to avoid collison with objects, rotates it, and saves the applied rotation to a vector3 gui.AddWindow("Orient Robot", oWindow, (object o) => { mainNode.transform.position = new Vector3(mainNode.transform.position.x, 1, mainNode.transform.position.z); switch ((int)o) { case 0: mainNode.transform.position = new Vector3(mainNode.transform.position.x, 1, mainNode.transform.position.z); mainNode.transform.Rotate(new Vector3(0, 0, 45)); break; case 1: mainNode.transform.position = new Vector3(mainNode.transform.position.x, 1, mainNode.transform.position.z); mainNode.transform.Rotate(new Vector3(0, 0, -45)); break; case 2: mainNode.transform.position = new Vector3(mainNode.transform.position.x, 1, mainNode.transform.position.z); mainNode.transform.Rotate(new Vector3(45, 0, 0)); break; case 3: mainNode.transform.position = new Vector3(mainNode.transform.position.x, 1, mainNode.transform.position.z); mainNode.transform.Rotate(new Vector3(-45, 0, 0)); break; case 4: rotation = mainNode.transform.rotation; Debug.Log(rotation); break; case 5: oWindow.Active = false; break; case 6: rotation = Quaternion.identity; mainNode.transform.rotation = rotation; break; } }); }
void OnGUI() { //Custom style for windows menuWindow = new GUIStyle(GUI.skin.window); menuWindow.normal.background = transparentWindowTexture; menuWindow.onNormal.background = transparentWindowTexture; menuWindow.font = russoOne; //Custom style for buttons menuButton = new GUIStyle(GUI.skin.button); menuButton.font = russoOne; menuButton.normal.background = buttonTexture; menuButton.hover.background = buttonSelected; menuButton.active.background = buttonSelected; menuButton.onNormal.background = buttonSelected; menuButton.onHover.background = buttonSelected; menuButton.onActive.background = buttonSelected; // Draws stats window on to GUI if (showStatWindow) { GUI.Window(0, statsWindowRect, StatsWindow, "Stats", statsWindow); } if (gui == null) { gui = new GUIController(); gui.hideGuiCallback = HideGuiSidebar; gui.showGuiCallback = ShowGuiSidebar; gui.AddWindow("Load Robot", new FileBrowser("Load Robot"), (object o) => { string fileLocation = (string)o; // If dir was selected... if (File.Exists(fileLocation + "\\skeleton.bxdj")) { fileLocation += "\\skeleton.bxdj"; } DirectoryInfo parent = Directory.GetParent(fileLocation); if (parent != null && parent.Exists && File.Exists(parent.FullName + "\\skeleton.bxdj")) { this.filePath = parent.FullName + "\\"; reloadRobotInFrames = 2; } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } dynamicCamera.EnableMoving(); }); gui.AddAction("Reset Robot", () => { resetRobot(); }); //shows button to manually orient the robot ShowOrient(); if (!File.Exists(filePath + "\\skeleton.bxdj")) { gui.DoAction("Load Model"); } gui.AddWindow("Switch View", new DialogWindow("Switch View", "Driver Station", "Orbit Robot", "Freeroam"), (object o) => { HideGuiSidebar(); switch ((int)o) { case 0: dynamicCamera.SwitchCameraState(new DynamicCamera.DriverStationState(dynamicCamera)); break; case 1: dynamicCamera.SwitchCameraState(new DynamicCamera.OrbitState(dynamicCamera)); dynamicCamera.EnableMoving(); break; case 2: dynamicCamera.SwitchCameraState(new DynamicCamera.FreeroamState(dynamicCamera)); break; default: Debug.Log("Camera state not found: " + (string)o); break; } }); gui.AddWindow("Quit to Main Menu", new DialogWindow("Quit to Main Menu?", "Yes", "No"), (object o) => { if ((int)o == 0) { Application.LoadLevel("MainMenu"); } }); gui.AddWindow("Quit to Desktop", new DialogWindow("Quit to Desktop?", "Yes", "No"), (object o) => { if ((int)o == 0) { Application.Quit(); } }); } if (Input.GetMouseButtonUp(0) && !gui.ClickedInsideWindow()) { HideGuiSidebar(); gui.HideAllWindows(); } if (fieldBrowser == null) { fieldBrowser = new FileBrowser("Load Field", false); fieldBrowser.Active = false; fieldBrowser.OnComplete += (object obj) => { fieldBrowser.Active = false; string fileLocation = (string)obj; // If dir was selected... if (File.Exists(fileLocation + "\\definition.bxdf")) { fileLocation += "\\definition.bxdf"; } DirectoryInfo parent = Directory.GetParent(fileLocation); if (parent != null && parent.Exists && File.Exists(parent.FullName + "\\definition.bxdf")) { this.filePath = parent.FullName + "\\"; fieldBrowser.Active = false; reloadFieldInFrames = 2; } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } }; } if (!fieldLoaded) { fieldBrowser.Render(); } else { // The Menu button on the top left corner GUI.Window(1, new Rect(0, 0, gui.GetSidebarWidth(), 25), (int windowID) => { if (GUI.Button(new Rect(0, 0, gui.GetSidebarWidth(), 25), "Menu", menuButton)) { gui.EscPressed(); } }, "", menuWindow ); gui.Render(); } UserMessageManager.Render(); if (reloadRobotInFrames >= 0 || reloadFieldInFrames >= 0) { GUI.backgroundColor = new Color(1, 1, 1, 0.5f); GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 25, 200, 25), "Loading... Please Wait", gui.BlackBoxStyle); } }
void OnGUI() { // Draws stats window on to GUI if (showStatWindow) { GUI.Window(0, statsWindowRect, StatsWindow, "Stats"); } // Draws help window on to GUI if (showHelpWindow) { int windowWidth = 900; int windowHeight = 450; float paddingX = (Screen.width - windowWidth) / 2.0f; float paddingY = (Screen.height - windowHeight) / 2.0f; helpWindowRect = new Rect(paddingX, paddingY, windowWidth, windowHeight); GUI.Window(0, helpWindowRect, HelpWindow, "Help"); } if (gui == null) { gui = new GUIController(); gui.hideGuiCallback = HideGuiSidebar; gui.showGuiCallback = ShowGuiSidebar; gui.AddWindow("Load Robot", new FileBrowser("Load Robot"), (object o) => { string fileLocation = (string)o; // If dir was selected... if (File.Exists(fileLocation + "\\skeleton.bxdj")) { fileLocation += "\\skeleton.bxdj"; } DirectoryInfo parent = Directory.GetParent(fileLocation); if (parent != null && parent.Exists && File.Exists(parent.FullName + "\\skeleton.bxdj")) { this.filePath = parent.FullName + "\\"; reloadRobotInFrames = 2; } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } dynamicCamera.EnableMoving(); }); gui.AddAction("Reset Robot", () => { resetRobot(); }); //shows button to manually orient the robot ShowOrient(); if (!File.Exists(filePath + "\\skeleton.bxdj")) { gui.DoAction("Load Model"); } gui.AddWindow("Switch View", new DialogWindow("Switch View", "Driver Station [D]", "Orbit Robot [R]", "Freeroam [F]"), (object o) => { HideGuiSidebar(); switch ((int)o) { case 0: dynamicCamera.SwitchCameraState(new DynamicCamera.DriverStationState(dynamicCamera)); break; case 1: dynamicCamera.SwitchCameraState(new DynamicCamera.OrbitState(dynamicCamera)); dynamicCamera.EnableMoving(); break; case 2: dynamicCamera.SwitchCameraState(new DynamicCamera.FreeroamState(dynamicCamera)); break; default: Debug.Log("Camera state not found: " + (string)o); break; } }); gui.AddWindow("Quit Simulation", new DialogWindow("Exit?", "Yes", "No"), (object o) => { if ((int)o == 0) { Application.Quit(); } }); } if (Input.GetMouseButtonUp(0) && !gui.ClickedInsideWindow()) { HideGuiSidebar(); gui.HideAllWindows(); } if (fieldBrowser == null) { fieldBrowser = new FileBrowser("Load Field", false); fieldBrowser.Active = true; fieldBrowser.OnComplete += (object obj) => { fieldBrowser.Active = true; string fileLocation = (string)obj; // If dir was selected... if (File.Exists(fileLocation + "\\definition.bxdf")) { fileLocation += "\\definition.bxdf"; } DirectoryInfo parent = Directory.GetParent(fileLocation); if (parent != null && parent.Exists && File.Exists(parent.FullName + "\\definition.bxdf")) { this.filePath = parent.FullName + "\\"; fieldBrowser.Active = false; reloadFieldInFrames = 2; } else { UserMessageManager.Dispatch("Invalid selection!", 10f); } }; } if (showHelpWindow && Input.GetMouseButtonUp(0) && !auxFunctions.MouseInWindow(helpWindowRect) && !auxFunctions.MouseInWindow(helpButtonRect)) { showHelpWindow = false; } gui.guiBackgroundVisible = showHelpWindow; if (!fieldLoaded) { fieldBrowser.Render(); } else { // The Menu button on the top left corner GUI.Window(1, new Rect(0, 0, gui.GetSidebarWidth(), 25), (int windowID) => { if (GUI.Button(new Rect(0, 0, gui.GetSidebarWidth(), 25), "Menu")) { gui.EscPressed(); } }, "" ); helpButtonRect = new Rect(Screen.width - 25, 0, 25, 25); // The Help button on top right corner GUI.Window(2, helpButtonRect, (int windowID) => { if (GUI.Button(new Rect(0, 0, 25, 25), helpButtonContent)) { showHelpWindow = !showHelpWindow; } }, "" ); gui.Render(); } UserMessageManager.Render(); if (reloadRobotInFrames >= 0 || reloadFieldInFrames >= 0) { GUI.backgroundColor = new Color(1, 1, 1, 0.5f); GUI.Box(new Rect(Screen.width / 2 - 100, Screen.height / 2 - 25, 200, 50), "Loading... Please Wait", gui.BlackBoxStyle); } }