예제 #1
0
    // screenCenterAsZero为true表示返回的坐标是以window的中心为原点,false表示已window的左下角为原点
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject window, bool screenCenterAsZero = true, bool isNGUI = true)
    {
        Camera  camera     = getUICamera(isNGUI);
        Vector2 cameraSize = new Vector2(camera.pixelWidth, camera.pixelHeight);
        Vector2 rootSize   = getRootSize(isNGUI);

        screenPos = multiVector2(devideVector2(screenPos, cameraSize), rootSize);
        // 将坐标转换到以屏幕中心为原点的坐标
        screenPos -= rootSize * 0.5f;
        Vector2 windowPos = screenPos;

        if (window != null)
        {
            txUIObject root = FrameBase.mLayoutManager.getUIRoot(isNGUI);
            Vector2    parentWorldPosition = devideVector3(window.getWorldPosition(), root.getScale());
            windowPos = devideVector2(screenPos - parentWorldPosition, window.getWorldScale());
            if (!screenCenterAsZero)
            {
                windowPos += window.getWindowSize() * 0.5f;
            }
        }
        else
        {
            if (!screenCenterAsZero)
            {
                windowPos += rootSize * 0.5f;
            }
        }
        return(windowPos);
    }
예제 #2
0
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent, bool screenCenterAsZero = false, bool isNGUI = true)
    {
        Camera  camera   = mCameraManager.getUICamera().getCamera();
        Vector2 rootSize = WidgetUtility.getRootSize();

        screenPos.x = screenPos.x / camera.pixelWidth * rootSize.x;
        screenPos.y = screenPos.y / camera.pixelHeight * rootSize.y;
        Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero;

        txUIObject root  = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    scale = root.getScale();

        parentWorldPosition.x = parentWorldPosition.x / scale.x;
        parentWorldPosition.y = parentWorldPosition.y / scale.y;
        Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one;

        Vector2 pos       = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y);
        Vector2 windowPos = new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y);

        if (screenCenterAsZero)
        {
            windowPos -= rootSize / 2;
        }
        return(windowPos);
    }
예제 #3
0
    protected override Vector3 getScreenPosition()
    {
        Camera camera = mCameraManager.getUICamera(mWindow.getLayout().isNGUI()).getCamera();

        if (camera != null)
        {
            return(camera.WorldToScreenPoint(mWindow.getWorldPosition()));
        }
        return(Vector3.zero);
    }
예제 #4
0
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent)
    {
        Camera camera = mCameraManager.getUICamera().getCamera();

        screenPos.x = screenPos.x / camera.pixelWidth * UnityEngine.Screen.currentResolution.width;
        screenPos.y = screenPos.y / camera.pixelHeight * UnityEngine.Screen.currentResolution.height;
        Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero;

        Vector3 scale = mLayoutManager.getUIRoot().getScale();

        parentWorldPosition.x = parentWorldPosition.x / scale.x;
        parentWorldPosition.y = parentWorldPosition.y / scale.y;
        Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one;

        Vector2 pos = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y);

        return(new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y));
    }
예제 #5
0
    public static Vector2 screenPosToWindowPos(Vector2 screenPos, txUIObject parent, bool screenCenterOsZero = false, bool isNGUI = true)
    {
        Camera camera = mCameraManager.getUICamera().getCamera();

        screenPos.x = screenPos.x / camera.pixelWidth * UnityEngine.Screen.currentResolution.width;
        screenPos.y = screenPos.y / camera.pixelHeight * UnityEngine.Screen.currentResolution.height;
        Vector3 parentWorldPosition = parent != null?parent.getWorldPosition() : Vector3.zero;

        txUIObject root  = isNGUI ? mLayoutManager.getNGUIRoot() : mLayoutManager.getUGUIRoot();
        Vector3    scale = root.getScale();

        parentWorldPosition.x = parentWorldPosition.x / scale.x;
        parentWorldPosition.y = parentWorldPosition.y / scale.y;
        Vector2 parentWorldScale = parent != null?parent.getWorldScale() : Vector2.one;

        Vector2 pos       = new Vector2(screenPos.x - parentWorldPosition.x, screenPos.y - parentWorldPosition.y);
        Vector2 windowPos = new Vector2(pos.x / parentWorldScale.x, pos.y / parentWorldScale.y);

        if (screenCenterOsZero)
        {
            windowPos -= new Vector2(UnityEngine.Screen.currentResolution.width / 2.0f, UnityEngine.Screen.currentResolution.height / 2.0f);
        }
        return(windowPos);
    }