Esempio n. 1
0
    //main tooltip edge of screen guard and movement - camera
    public void OnScreenSpaceCamera(bool refreshCanvasesBeforeGettingSize = false)
    {
        baseTooltipPos.z = canvas.planeDistance;

        newTTPos         = GuiCamera.ScreenToViewportPoint(baseTooltipPos - offset);
        adjustedNewTTPos = GuiCamera.ViewportToWorldPoint(newTTPos);

        adjustedPivot        = originalPivot;
        _rectTransform.pivot = originalPivot;

        gameObject.SetActive(true);

        if (refreshCanvasesBeforeGettingSize)
        {
            RefreshTooltipSize();
        }

        //consider scaled dimensions when comparing against the edges
        CalcTooltipVerticalDimensions(true);
        CalcTooltipHorizontalDimensions(true);

        //get screen bounds in the canvas's rect
        RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, Vector2.zero, GuiCamera, out screenLowerLeft);
        RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, new Vector2(Screen.width, Screen.height), GuiCamera, out screenUpperRight);

        BorderAdjustments(true);

        _rectTransform.pivot = adjustedPivot;

        //failed attempt to circumvent issues caused when rotating the camera
        adjustedNewTTPos = transform.rotation * adjustedNewTTPos;

        transform.position      = adjustedNewTTPos;
        adjustedTTLocalPos      = transform.localPosition;
        adjustedTTLocalPos.z    = 0;
        transform.localPosition = adjustedTTLocalPos;

        _inside = true;
    }
Esempio n. 2
0
        //main tooltip edge of screen guard and movement - camera
        public void OnScreenSpaceCamera(bool refreshCanvasesBeforeGettingSize = false)
        {
            shiftingVector.x = xShift;
            shiftingVector.y = YShift;

            baseTooltipPos.z = canvas.planeDistance;

            newTTPos         = GuiCamera.ScreenToViewportPoint(baseTooltipPos - shiftingVector);
            adjustedNewTTPos = GuiCamera.ViewportToWorldPoint(newTTPos);

            gameObject.SetActive(true);

            if (refreshCanvasesBeforeGettingSize)
            {
                RefreshTooltipSize();
            }

            //consider scaled dimensions when comparing against the edges
            width  = transform.lossyScale.x * _rectTransform.sizeDelta[0];
            height = transform.lossyScale.y * _rectTransform.sizeDelta[1];

            // check and solve problems for the tooltip that goes out of the screen on the horizontal axis

            RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, Vector2.zero, GuiCamera, out screenLowerLeft);
            RectTransformUtility.ScreenPointToWorldPointInRectangle(canvasRectTransform, new Vector2(Screen.width, Screen.height), GuiCamera, out screenUpperRight);


            //check for right edge of screen
            borderTest = (adjustedNewTTPos.x + width / 2);
            if (borderTest > screenUpperRight.x)
            {
                shifterForBorders.x = borderTest - screenUpperRight.x;
                adjustedNewTTPos.x -= shifterForBorders.x;
            }
            //check for left edge of screen
            borderTest = (adjustedNewTTPos.x - width / 2);
            if (borderTest < screenLowerLeft.x)
            {
                shifterForBorders.x = screenLowerLeft.x - borderTest;
                adjustedNewTTPos.x += shifterForBorders.x;
            }

            // check and solve problems for the tooltip that goes out of the screen on the vertical axis

            //check for lower edge of the screen
            borderTest = (adjustedNewTTPos.y - height / 2);
            if (borderTest < screenLowerLeft.y)
            {
                shifterForBorders.y = screenLowerLeft.y - borderTest;
                adjustedNewTTPos.y += shifterForBorders.y;
            }

            //check for upper edge of the screen
            borderTest = (adjustedNewTTPos.y + height / 2);
            if (borderTest > screenUpperRight.y)
            {
                shifterForBorders.y = borderTest - screenUpperRight.y;
                adjustedNewTTPos.y -= shifterForBorders.y;
            }

            //failed attempt to circumvent issues caused when rotating the camera
            adjustedNewTTPos = transform.rotation * adjustedNewTTPos;

            transform.position      = adjustedNewTTPos;
            adjustedTTLocalPos      = transform.localPosition;
            adjustedTTLocalPos.z    = 0;
            transform.localPosition = adjustedTTLocalPos;

            _inside = true;
        }