Beispiel #1
0
        public bool isWaterSurfaceOnScreen()
        {
            if (!cameraFollow)
            {
                cameraFollow = Camera.main.GetComponent <cameraFollowPlayer>();
            }
            if (!cameraFollow)
            {
                return(true);
            }
            float cl = cameraFollow.getLeftViewX() - 1f;
            float cr = cameraFollow.getRightViewX() + 1f;
            float ct = cameraFollow.getTopViewY() + 1f;
            float cb = cameraFollow.getBottomViewY() - 1f;

            Rect cam = new Rect(cl, cb, cr - cl, ct - cb);

            if (cam.Overlaps(new Rect(bound.left, bound.top, bound.right, bound.top + 1f)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
    //Updates the positioning of the dialog box on the screen
    void UpdatePosition()
    {
        float halfW     = (bgRect.rect.width / 2) * canvasComponent.scaleFactor;
        float halfH     = (bgRect.rect.height / 2) * canvasComponent.scaleFactor;
        float tailHalfW = (tailRect.rect.width / 2) * canvasComponent.scaleFactor;
        float tailHalfH = (tailRect.rect.height / 2) * canvasComponent.scaleFactor;
        float tailX     = 0;
        float tailY     = 0;
        bool  tailFlip  = false;

        float leftViewEdge = 0f + screenEdgeBuffer.x, rightViewEdge = Screen.width - screenEdgeBuffer.x, topViewEdge = Screen.height, bottomViewEdge = 0f;

        if (playerCam != null)
        {
            leftViewEdge   = Camera.main.WorldToScreenPoint(new Vector3(playerCam.getLeftViewX(), 0f, 0f)).x;
            rightViewEdge  = Camera.main.WorldToScreenPoint(new Vector3(playerCam.getRightViewX(), 0f, 0f)).x;
            topViewEdge    = Camera.main.WorldToScreenPoint(new Vector3(0f, playerCam.getTopViewY(), 0f)).y;
            bottomViewEdge = Camera.main.WorldToScreenPoint(new Vector3(0f, playerCam.getBottomViewY(), 0f)).y;
        }

        Vector3 pos = new Vector3(0f, 0f, 0f);

        if (followTop != null)
        {
            pos    = Camera.main.WorldToScreenPoint(followTop.position + new Vector3(dbOffset.x, dbOffset.y, 0)) + new Vector3(0f, tailHalfH * 2, 0f);
            pos.y += halfH;
            tailY  = pos.y - halfH - (tailHalfH);
        }

        //Move the box under the character if it would fit better on the screen, or if we've only specified a bottom transform
        if (followBottom != null && (pos.y > (topViewEdge - halfH) || followTop == null))
        {
            pos    = Camera.main.WorldToScreenPoint(followBottom.position + new Vector3(dbOffset.x, dbOffset.y, 0)) + new Vector3(0f, tailHalfH * 2, 0f);
            pos.y -= halfH;

            tailY    = pos.y + halfH + (tailHalfH);
            tailFlip = true;
        }

        tailX = pos.x;


        if (stayOnScreen)
        {
            if (pos.x < leftViewEdge + halfW)
            {
                pos.x = leftViewEdge + halfW + screenEdgeBuffer.x;
            }
            if (pos.x > (rightViewEdge - halfW))
            {
                pos.x = (rightViewEdge - halfW) - screenEdgeBuffer.x;
            }
        }

        //If no transform is provided, just put the box in the middle of the screen
        if (followTop == null && followBottom == null)
        {
            pos = new Vector3((rightViewEdge / 2), (topViewEdge / 2), 0f);
            tail.SetActive(false);
        }
        else
        {
            tail.SetActive(true);
            tail.transform.localScale = new Vector3(tail.transform.localScale.x, tailFlip ? -1 : 1, tail.transform.localScale.z);
            tail.transform.position   = new Vector3(tailX, tailY, 0f);
        }

        if (tailX < tailBufferX && stayOnScreen)
        {
            //tailX = leftViewEdge + tailBufferX;
            tail.SetActive(false);
        }
        if (tailX > (rightViewEdge - tailBufferX) && stayOnScreen)
        {
            //tailX = rightViewEdge - tailBufferX;
            tail.SetActive(false);
        }

        dBox.transform.position = pos;
    }