public void Awake() { Instance = this; canvas = GameObject.Find("Canvas"); mainPanel = Auxiliary.FindObject(canvas, "RobotIOPanel"); mainPanel.SetActive(false); // Must start inactive, otherwise initializing mini camera will cause problems displayPanel = Auxiliary.FindObject(mainPanel, "RobotIODisplayPanel"); robotIOGroups = new RobotIOGroup[(int)Enum.GetValues(typeof(RobotIOGroup.Type)).Cast <RobotIOGroup.Type>().Max() + 1]; // Set size to number of enum values miniCameraView = Auxiliary.FindObject(mainPanel, "MiniCameraView"); robotPrintPanel = Auxiliary.FindObject(mainPanel, "RobotPrintPanel"); robotPrintScrollRect = Auxiliary.FindObject(robotPrintPanel, "RobotPrintScrollRect"); robotPrintScrollContent = Auxiliary.FindObject(robotPrintScrollRect, "Content"); robotPrintTextContainer = Auxiliary.FindObject(robotPrintScrollContent, "PrintContainer"); robotPrintFooter = Auxiliary.FindObject(robotPrintPanel, "RobotPrintFooter"); autoScrollButtonImage = Auxiliary.FindObject(robotPrintFooter, "RobotPrintAutoScrollButton").GetComponent <Image>(); autoScrollButtonImage.sprite = SelectedButtonImage; enablePrintsButtonImage = Auxiliary.FindObject(robotPrintFooter, "EnableRobotPrintButton").GetComponent <Image>(); enablePrintsButtonImage.sprite = SelectedButtonImage; RobotPrintManager.Init(); Populate(); }
/// <summary> /// Toggles whether the print-out panel automatically scrolls down to the most recent prints /// </summary> public void ToggleAutoScroll() { autoScroll = !autoScroll; autoScrollButtonImage.sprite = autoScroll ? SelectedButtonImage : UnselectedButtonImage; if (autoScroll) { RobotPrintManager.ScrollToBottom(); } }
public void Update() { if (shouldBeActive) // Handle hiding the panel. Other UIs don't hide automatically, but this one is big and should. { if (InputControl.GetButtonDown(new KeyMapping("Hide Menu", KeyCode.H, Input.Enums.KeyModifier.Ctrl), true)) // TODO make global control { mainPanel.SetActive(!mainPanel.activeSelf); } } if (mainPanel.activeSelf) // Update rest of UI { bool anyFieldfocused = false; foreach (var group in robotIOGroups) { anyFieldfocused = anyFieldfocused || group.Update(); } if (anyFieldfocused != lastAnyFieldfocused) { InputControl.freeze = anyFieldfocused; // Prevent users inputting values from triggering controls lastAnyFieldfocused = anyFieldfocused; } if (miniCamera == null) { InitMiniCamera(); } UpdateMiniCamera(); Resize(); DynamicCamera.ControlEnabled = false; } else if (lastActive) { DynamicCamera.ControlEnabled = true; } if (enablePrints && EmulatorManager.IsTryingToRunRobotCode() && !EmulatorManager.IsRobotCodeRestarting()) // Update robot prints { RobotPrintManager.Update(); } lastActive = mainPanel.activeSelf; }
/// <summary> /// Resize the UI so it scales with different resolutions and aspect ratios /// </summary> /// <param name="forceUpdate"></param> private void Resize(bool forceUpdate = false) { if (!lastSetPixelRect.Equals(UnityEngine.Camera.main.pixelRect) || forceUpdate) { // Update size of mini camera to match the camera aspect ratio try { var size_delta = miniCameraView.GetComponent <RectTransform>().sizeDelta; // Maintain main camera aspect ratio in mini camera view miniCameraView.GetComponent <RectTransform>().sizeDelta = new Vector2( size_delta.y * UnityEngine.Camera.main.aspect, size_delta.y); // Update camera texture size as well if (miniCamera.targetTexture != null) { miniCamera.targetTexture.Release(); } miniCamera.targetTexture = new RenderTexture(new RenderTextureDescriptor( UnityEngine.Camera.main.pixelWidth, UnityEngine.Camera.main.pixelHeight)); miniCameraView.GetComponent <RawImage>().texture = miniCamera.targetTexture; // Fill remaining width of screen with the robot print panel robotPrintPanel.GetComponent <LayoutElement>().preferredWidth = (UnityEngine.Camera.main.pixelRect.width - size_delta.x) / size_delta.x; robotPrintScrollRect.GetComponent <LayoutElement>().preferredHeight = robotPrintPanel.GetComponent <RectTransform>().sizeDelta.y - robotPrintFooter.GetComponent <RectTransform>().sizeDelta.y; lastSetPixelRect = UnityEngine.Camera.main.pixelRect; } catch (Exception e) { Debug.Log(e.ToString()); } } RobotPrintManager.Resize(forceUpdate); }
/// <summary> /// Reset the robot print-out console /// </summary> public void ClearPrintConsole() { RobotPrintManager.Clear(); }