예제 #1
0
        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 (PlayerPrefs.GetInt("analytics") == 1) //for analytics tracking
                {
                    Analytics.CustomEvent("Changed Field", new Dictionary <string, object>
                    {
                    });
                }
                //FieldDataHandler.Load();
                //DPMDataHandler.Load();
                //Controls.Init();
                //Controls.Load();
                SceneManager.LoadScene("Scene");
            }
            else
            {
                UserMessageManager.Dispatch("Field directory not found!", 5);
            }
        }
예제 #2
0
        public void ChangeRobot()
        {
            GameObject panel     = GameObject.Find("RobotListPanel");
            string     directory = PlayerPrefs.GetString("RobotDirectory") + Path.DirectorySeparatorChar + panel.GetComponent <ChangeRobotScrollable>().selectedEntry;

            if (Directory.Exists(directory))
            {
                panel.SetActive(false);
                changeRobotPanel.SetActive(false);
                InputControl.EnableSimControls();
                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();

                AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.ChangeRobot,
                                                              AnalyticsLedger.EventAction.Clicked,
                                                              "Robot - Exported",
                                                              AnalyticsLedger.getMilliseconds().ToString());

                robotCameraManager.DetachCamerasFromRobot(State.ActiveRobot);
                sensorManager.RemoveSensorsFromRobot(State.ActiveRobot);

                State.ChangeRobot(directory, false);
                RobotTypeManager.IsMixAndMatch = false;
            }
            else
            {
                UserMessageManager.Dispatch("Robot directory not found!", WARNING_TIME);
            }
        }
예제 #3
0
        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 (PlayerPrefs.GetInt("analytics") == 1) //for analytics tracking
                {
                    Analytics.CustomEvent("Changed Robot", new Dictionary <string, object>
                    {
                    });
                }

                robotCameraManager.DetachCamerasFromRobot(State.ActiveRobot);
                sensorManager.RemoveSensorsFromRobot(State.ActiveRobot);

                State.ChangeRobot(directory, false);
                RobotTypeManager.IsMixAndMatch = false;
            }
            else
            {
                UserMessageManager.Dispatch("Robot directory not found!", 5);
            }
        }
예제 #4
0
        public async void RestartRobotCode()
        {
            if (EmulationWarnings.CheckRequirement(EmulationWarnings.Requirement.UserProgramPresent) && EmulationWarnings.CheckRequirement(EmulationWarnings.Requirement.UserProgramNotRestarting))
            {
                bool success = await EmulatorManager.RestartRobotCode();

                if (!success)
                {
                    UserMessageManager.Dispatch("Failed to restart user program", EmulationWarnings.WARNING_DURATION);
                }
            }
        }
예제 #5
0
 public void OnScoringTab()
 {
     if (FieldDataHandler.gamepieces.Count > 0)
     {
         if (helpMenu.activeSelf)
         {
             CloseHelpMenu("ScoringToolbar");
         }
         currentTab = "ScoringTab";
         tabStateMachine.ChangeState(new ScoringToolbarState());
     }
     else
     {
         UserMessageManager.Dispatch("No Gamepieces Available In Field. Scoring Disabled.", 3);
     }
 }
예제 #6
0
        public void ToggleRobotPrints()
        {
            bool newEnable = !enablePrints;

            // TODO warn and wait if last command didnt finish
            if (!enablePrints && newEnable && EmulatorManager.IsRobotOutputStreamGood()) // When trying to enable, wait until old connection closes
            {
                UserMessageManager.Dispatch("Waiting to close last readout connection", EmulationWarnings.WARNING_DURATION);
            }
            else
            {
                enablePrints = newEnable;
                enablePrintsButtonImage.sprite = enablePrints ? SelectedButtonImage : UnselectedButtonImage;
                if (enablePrints && !EmulatorManager.IsTryingToRunRobotCode())
                {
                    UserMessageManager.Dispatch("Readout enabled, waiting for robot program to start", EmulationWarnings.WARNING_DURATION);
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Track joystick connections and disconnections
        /// </summary>
        /// <param name="warn">Whether to dispatch warnings on change or not</param>
        private void UpdateJoystickStates(bool warn = true)
        {
            var newJoystickNames = UnityEngine.Input.GetJoystickNames();

            for (var i = 0; i < lastJoystickNmaes.Length; i++)
            {
                string newState = (i < newJoystickNames.Length && !string.IsNullOrEmpty(newJoystickNames[i])) ? newJoystickNames[i] : null;
                if (warn && newState != lastJoystickNmaes[i])
                {
                    if (newState != null)
                    {
                        UserMessageManager.Dispatch("Connected - Joystick " + (i + 1) + " " + newState, 6);
                    }
                    else
                    {
                        UserMessageManager.Dispatch("Disconnected - Joystick " + (i + 1) + " " + lastJoystickNmaes[i], 6);
                    }
                }
                lastJoystickNmaes[i] = newState;
            }
        }
예제 #8
0
        public void OnScoringTab()
        {
            AnalyticsManager.GlobalInstance.LogTimingAsync(AnalyticsLedger.TimingCatagory.ScoringTab,
                                                           AnalyticsLedger.TimingVarible.Customizing,
                                                           AnalyticsLedger.TimingLabel.MainSimulator); // log any timing events from switching tabs
            AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.ScoringTab,
                                                          AnalyticsLedger.EventAction.Clicked,
                                                          "Tab",
                                                          AnalyticsLedger.getMilliseconds().ToString()); // log the button was clicked
            AnalyticsManager.GlobalInstance.StartTime(AnalyticsLedger.TimingLabel.ScoringTab,
                                                      AnalyticsLedger.TimingVarible.Customizing);        // start timer for current tab

            if (FieldDataHandler.gamepieces.Count > 0)
            {
                currentTab = "ScoringTab";
                tabStateMachine.ChangeState(new ScoringToolbarState());
            }
            else
            {
                UserMessageManager.Dispatch("No Gamepieces Available In Field. Scoring Disabled.", WARNING_TIME);
            }
        }
예제 #9
0
        public void ChangeField()
        {
            GameObject panel     = GameObject.Find("FieldListPanel");
            string     directory = PlayerPrefs.GetString("FieldDirectory") + Path.DirectorySeparatorChar + panel.GetComponent <ChangeFieldScrollable>().selectedEntry;

            if (Directory.Exists(directory))
            {
                panel.SetActive(false);
                changeFieldPanel.SetActive(false);
                InputControl.EnableSimControls();
                loadingPanel.SetActive(true);
                PlayerPrefs.SetString("simSelectedReplay", string.Empty);
                PlayerPrefs.SetString("simSelectedField", directory);
                PlayerPrefs.SetString("simSelectedFieldName", panel.GetComponent <ChangeFieldScrollable>().selectedEntry);
                PlayerPrefs.Save();

                AnalyticsManager.GlobalInstance.LogTimingAsync(AnalyticsLedger.TimingCatagory.MainSimulator,
                                                               AnalyticsLedger.TimingVarible.Playing,
                                                               AnalyticsLedger.TimingLabel.ResetField);
                AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.ChangeField,
                                                              AnalyticsLedger.EventAction.Changed,
                                                              panel.GetComponent <ChangeFieldScrollable>().selectedEntry.ToString(),
                                                              AnalyticsLedger.getMilliseconds().ToString());

                //FieldDataHandler.LoadFieldMetaData(directory);
                //DPMDataHandler.Load();
                //Controls.Load();
                SceneManager.LoadScene("Scene");

                AnalyticsManager.GlobalInstance.StartTime(AnalyticsLedger.TimingLabel.ChangeField,
                                                          AnalyticsLedger.TimingVarible.Playing); // start timer for current field
            }
            else
            {
                UserMessageManager.Dispatch("Field directory not found!", WARNING_TIME);
            }
        }
예제 #10
0
        public SynthesisFileBrowser(string windowTitle, string defaultDirectory, bool allowEsc = true)
        {
            DirectoryInfo directorySelection;

            if (Directory.Exists(defaultDirectory))
            {
                directoryPath = defaultDirectory;
            }
            Init(windowTitle, defaultDirectory, allowEsc);

            directorySelection = new DirectoryInfo(defaultDirectory);

            if (defaultDirectory != null)
            {
                //Use try/catch to prevent users from getting in unauthorized folders
                try
                {
                    //If directory contains field or robot files, display error message to user prompting them to select directory
                    //instead of the actual field
                    if (directorySelection.GetFiles("*.bxdf").Length != 0 || directorySelection.GetFiles("*.bxda").Length != 0 ||
                        directorySelection.GetFiles("*.bxdj").Length != 0)
                    {
                        UserMessageManager.Dispatch("Please DO NOT select the field/robot itself!", 5);
                        directorySelection = directorySelection.Parent;
                        directoryPath      = directorySelection.FullName;
                        directoryLocation  = directorySelection.FullName;
                        defaultDirectory   = directorySelection.FullName;
                        defaultDirectory   = directoryLocation;
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    UserMessageManager.Dispatch("You don't have the authorization to access this folder", 3f);
                }
            }
        }
예제 #11
0
 /// <summary>
 /// Runs every frame to update the GUI elements.
 /// </summary>
 void OnGUI()
 {
     UserMessageManager.scale = canvas.scaleFactor;
     UserMessageManager.Render();
 }
예제 #12
0
 /// <summary>
 /// Runs every frame to update the GUI elements.
 /// </summary>
 void OnGUI()
 {
     //Renders the message manager which displays error messages
     UserMessageManager.Render();
     UserMessageManager.scale = canvas.scaleFactor;
 }
예제 #13
0
 private void OnGUI()
 {
     UserMessageManager.Render();
 }
예제 #14
0
        /// <summary>
        /// Renders the browser window.
        /// </summary>
        /// <param name="idx">Window index</param>
        private void FileBrowserWindow(int idx)
        {
            DirectoryInfo directoryInfo;
            DirectoryInfo directorySelection;

            // Get the directory info of the current location
            FileInfo fileSelection = new FileInfo(directoryLocation);

            if ((fileSelection.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
            {
                directoryInfo = new DirectoryInfo(directoryLocation);
                //If there is no directory in the current location go back to its parent folder
                if (directoryInfo.GetDirectories().Length == 0 && title.Equals("Load Robot"))
                {
                    directoryInfo = directoryInfo.Parent;
                }
            }
            else
            {
                directoryInfo = fileSelection.Directory;
            }

            //If click Exit, close file browser
            if (_allowEsc && UnityEngine.GUI.Button(new Rect(410, 10, 80, 20), "Exit", fileBrowserButton))
            {
                Active = false;
            }

            //If hit Up One Level, go back to parent folder level
            if (directoryInfo.Parent != null && UnityEngine.GUI.Button(new Rect(10, 10, 120, 25), "Up One Level", fileBrowserButton))
            {
                directoryInfo             = directoryInfo.Parent;
                directoryLocation         = directoryInfo.FullName;
                selectedDirectoryLocation = directoryInfo.FullName;
                tempSelection             = null;
                //Reset the target folder list and set the folder to unsearched
                targetFolderList.Clear();
                directorySearched = false;
            }

            // Handle the directories list
            GUILayout.BeginArea(new Rect(10, 35, 480, 300));

            GUILayout.Label("When choosing a folder, please select the field/robot folder containing these elements" +
                            " " + "NOT the field/robot itself!", descriptionStyle);

            directoryScroll = GUILayout.BeginScrollView(directoryScroll);

            //Create a scrolling list and all the buttons having the folder names
            directorySelection = SelectList(directoryInfo.GetDirectories(), (DirectoryInfo o) =>
            {
                return(o.Name);
            }, new DirectoryInfo(directoryLocation).Name, targetFolderList) as DirectoryInfo;

            GUILayout.EndScrollView();
            GUILayout.EndArea();

            if (directorySelection != null && selectedDirectoryLocation != null)
            {
                bool doubleClick = directorySelection != null && (Time.time - lastClick) > 0 && (Time.time - lastClick) < DOUBLE_CLICK_TIME;
                //Use try/catch to prevent users from getting in unauthorized folders
                try
                {
                    if (doubleClick)
                    {
                        // If directory contains field or robot files, display error message to user prompting them to select directory
                        // instead of the actual field
                        if (directorySelection.GetFiles("*.bxdf").Length != 0 || directorySelection.GetFiles("*.bxda").Length != 0 ||
                            directorySelection.GetFiles("*.bxdj").Length != 0)
                        {
                            UserMessageManager.Dispatch("Please DO NOT select the field/robot itself!", 5);
                        }
                        else
                        {
                            // If a directory without robot/field files was double clicked, jump there
                            directoryLocation = directorySelection.FullName;

                            targetFolderList.Clear();
                            directorySearched = false;
                        }
                        tempSelection = null;
                    }
                    else
                    {
                        // If directory contains field or robot files, display error message to user prompting them to select directory
                        // instead of the actual field
                        if (directorySelection.GetFiles("*.bxdf").Length != 0 || directorySelection.GetFiles("*.bxda").Length != 0 ||
                            directorySelection.GetFiles("*.bxdj").Length != 0)
                        {
                            UserMessageManager.Dispatch("Please DO NOT select the field/robot itself!", 5);
                        }
                        else
                        {
                            // If directory was clicked once, select it as a current path and highlight it
                            selectedDirectoryLocation = directorySelection.FullName;
                        }
                    }
                }
                catch (UnauthorizedAccessException e)
                {
                    UserMessageManager.Dispatch("You don't have the authorization to access this folder", 3f);
                }
            }

            // The manual location box and the select button
            GUILayout.BeginArea(new Rect(12, 335, 480, 25));
            //GUILayout.BeginHorizontal();
            const int labelLen = 70;

            bool twoClicks = directorySelection != null && (Time.time - lastClick) > 0 && (Time.time - lastClick) < DOUBLE_CLICK_TIME;

            try
            {
                if (twoClicks)
                {
                    //If the file path is greater than labelLen, then it will replace part of the path name with "..."
                    GUILayout.Label(directoryLocation.Length > labelLen ?
                                    directoryLocation.Substring(0, 5) + "..." + directoryLocation.Substring(directoryLocation.Length - labelLen + 8) :
                                    directoryLocation, pathLabel);
                }
                else
                {
                    //One click displays the path of the selected folder
                    GUILayout.Label(selectedDirectoryLocation.Length > labelLen ?
                                    selectedDirectoryLocation.Substring(0, 5) + "..." +
                                    selectedDirectoryLocation.Substring(selectedDirectoryLocation.Length - labelLen + 8) :
                                    selectedDirectoryLocation, pathLabel);
                }
            }
            catch (UnauthorizedAccessException e)
            {
                UserMessageManager.Dispatch("You don't have the authorization to access this folder", 3f);
            }
            GUILayout.EndArea();
            GUILayout.BeginArea(new Rect(12, 360, 480, 25));
            GUILayout.BeginHorizontal();

            //When this button is clicked, search the directory for target files
            if (!directorySearched)
            {
                if (GUILayout.Button("Search for Target Directory", fileBrowserButton, GUILayout.Width(250)))
                {
                    SearchDirectories(directoryInfo);

                    //Notify the user there's nothing related inside the current directory
                    if (targetFolderList.Count == 0)
                    {
                        if (title.Equals("Choose Robot Directory"))
                        {
                            UserMessageManager.Dispatch("No exported robot files found in current directory", 5f);
                        }
                        else if (title.Equals("Choose Field Directory"))
                        {
                            UserMessageManager.Dispatch("No exported robot files found in current directory", 5f);
                        }
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Search for Target Directory", searchedButton, GUILayout.Width(250)))
                {
                    UserMessageManager.Dispatch("The current directory has been searched.", 5f);
                }
            }
            if (GUILayout.Button("Select", fileBrowserButton, GUILayout.Width(68)))
            {
                _active = false;
                OnComplete?.Invoke(selectedDirectoryLocation);
            }
            if (directorySelection != null)
            {
                lastClick = Time.time;
            }

            GUILayout.EndHorizontal();
            GUILayout.EndArea();
            GUILayout.BeginArea(new Rect(12, 385, 480, 25));
            GUILayout.Label("Searching through a large directory takes time. Please be patient :)", descriptionStyle);
            GUILayout.EndArea();
        }