public void SetCenterPosition(Vector2 screenPoint) { var flippedScreenPoint = new Vector2(screenPoint.x, Screen.height - screenPoint.y); var panelPoint = RuntimePanelUtils.ScreenToPanel(m_UiRoot.rootVisualElement.panel, flippedScreenPoint); m_Container.style.left = panelPoint.x; m_Container.style.top = panelPoint.y; }
private void UpdateCache() { cacheFrame = Time.frameCount; Vector2 screenSize = new(Screen.width, Screen.height); Vector2 stpMin = RuntimePanelUtils.ScreenToPanel(panel, new Vector2(0, 0)); Vector2 stpMax = RuntimePanelUtils.ScreenToPanel(panel, screenSize); Vector2 stpSize = stpMax - stpMin; screenHeight = screenSize.y; panelScreenMin = stpMin; scalingRatio = screenSize / stpSize; }
private void LayoutChanged(GeometryChangedEvent e) { var safeArea = Screen.safeArea; try { var leftTop = RuntimePanelUtils.ScreenToPanel(panel, new Vector2(safeArea.xMin, Screen.height - safeArea.yMax)); var rightBottom = RuntimePanelUtils.ScreenToPanel(panel, new Vector2(Screen.width - safeArea.xMax, safeArea.yMin)); style.marginLeft = leftTop.x; style.marginTop = leftTop.y; style.marginRight = rightBottom.x; style.marginBottom = rightBottom.y; } catch (InvalidCastException) {} }
void OnGeometryChanged(GeometryChangedEvent e) { var panel = this.panel; #if UNITY_EDITOR if (panel.contextType == ContextType.Editor) { //TODO: Is it possible to do the same in the editor? return; } #endif var safeArea = Screen.safeArea; var lt = RuntimePanelUtils.ScreenToPanel(panel, new Vector2(safeArea.xMin, Screen.height - safeArea.yMax)); var rb = RuntimePanelUtils.ScreenToPanel(panel, new Vector2(Screen.width - safeArea.xMax, safeArea.yMin)); { this.style.paddingLeft = lt.x; this.style.paddingTop = lt.y; this.style.paddingRight = rb.x; this.style.paddingBottom = rb.y; } }
public Vector2 ScreenToPanel(Vector2 v) { return(RuntimePanelUtils.ScreenToPanel(panel, v)); }