Beispiel #1
0
    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;
    }
Beispiel #2
0
    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;
    }
Beispiel #3
0
    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) {}
    }
Beispiel #4
0
        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;
            }
        }
Beispiel #5
0
 public Vector2 ScreenToPanel(Vector2 v)
 {
     return(RuntimePanelUtils.ScreenToPanel(panel, v));
 }