예제 #1
0
파일: Init.cs 프로젝트: solomondg/synthesis
    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);
        }
    }
예제 #2
0
    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);
        }
    }