当前位置: 首页>>代码示例>>C#>>正文


C# Camera.ViewportToScreenPoint方法代码示例

本文整理汇总了C#中UnityEngine.Camera.ViewportToScreenPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Camera.ViewportToScreenPoint方法的具体用法?C# Camera.ViewportToScreenPoint怎么用?C# Camera.ViewportToScreenPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Camera的用法示例。


在下文中一共展示了Camera.ViewportToScreenPoint方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    // Use this for initialization
    void Start()
    {
        // Try default camera
        cameraObject = GameObject.Find("Camera");
        myCamera = (Camera) cameraObject.GetComponent("Camera");

        planeSize = myCamera.ViewportToScreenPoint(this.transform.position);
        planeSize.x -= Screen.width;
        planeSize.y -= Screen.height;
    }
开发者ID:hagish,项目名称:newsupermeatboy,代码行数:11,代码来源:ParallaxScrolling.cs

示例2: CalculateBoxFromCntr

    /// <summary>
    /// Calculates the box surrounding the of the unit.
    /// </summary>
    /// <returns>The box</returns>
    /// <param name="cntr">The center of the unit</param>
    public static Rect CalculateBoxFromCntr(Vector3 cntr, Camera cam, int pix)
    {
        Rect box = new Rect();

        Vector3 actor_cntr = cam.WorldToViewportPoint(cntr);
        actor_cntr = cam.ViewportToScreenPoint(actor_cntr);
        Debug.Log(actor_cntr.x + " : " + actor_cntr.y + " : " + actor_cntr.z);

        box.xMin = actor_cntr.x - pix;
        box.xMax = actor_cntr.x + pix;
        box.yMin = Screen.height - actor_cntr.y - pix;
        box.yMax = Screen.height - actor_cntr.y + pix;

        return box;

    }
开发者ID:srferran,项目名称:ES2015A,代码行数:21,代码来源:AreaMarker.cs

示例3: ViewportToScreenY

 public float ViewportToScreenY(Camera camera, float viewportY)
 {
     return camera.ViewportToScreenPoint(new Vector2(0, viewportY)).y;
 }
开发者ID:Lirianer,项目名称:Debora,代码行数:4,代码来源:TGGBehaviour.cs

示例4: ViewportToScreenX

 public float ViewportToScreenX(Camera camera, float viewportX)
 {
     return camera.ViewportToScreenPoint(new Vector2(viewportX, 0)).x;
 }
开发者ID:Lirianer,项目名称:Debora,代码行数:4,代码来源:TGGBehaviour.cs

示例5: ViewportToCameraPoint

 public static Vector2 ViewportToCameraPoint(Camera cam, Vector2 viewportPoint)
 {
     return (Vector2)cam.ViewportToScreenPoint(viewportPoint) - new Vector2(cam.rect.x * Screen.width, cam.rect.y * Screen.height);
 }
开发者ID:christuart,项目名称:Meet-EDSAC,代码行数:4,代码来源:Tools.cs

示例6: GetPerspectiveWidth


//.........这里部分代码省略.........
            //Debug.Log(screenCoor);
        }

        //Fix for weird thing with only seeing one plane (ask me, or not. Rather dont actually)
        Vector3 firstClosest = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        Vector3 secondClosest = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        Vector3 thirdClosest = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
        if (originalLeft.x == originalRight.x || originalRight.z == originalLeft.z)
        {

            foreach (Vector3 coor in cornerCoordinates)
            {
                if (Vector3.Distance(camera.transform.position, thirdClosest) >= Vector3.Distance(camera.transform.position, coor))
                {
                    thirdClosest = coor;
                    if (Vector3.Distance(camera.transform.position, secondClosest) >= Vector3.Distance(camera.transform.position, thirdClosest))
                    {
                        Vector3 placeholder = secondClosest;
                        secondClosest = thirdClosest;
                        thirdClosest = placeholder;
                        if (Vector3.Distance(camera.transform.position, firstClosest) >= Vector3.Distance(camera.transform.position, secondClosest))
                        {
                            Vector3 placeholder2 = firstClosest;
                            firstClosest = secondClosest;
                            secondClosest = placeholder2;
                        }
                    }
                }
            }

            //Vector3

            if (Mathf.Abs(objBounds.center.x - camera.transform.position.x) <= Mathf.Abs(objBounds.center.x - firstClosest.x))
            {
                if (firstClosest.z == thirdClosest.z)
                {
                    secondClosest = thirdClosest;
                }
            }
            else
            {
                //dan is ie in de z categorie
                if (firstClosest.x == thirdClosest.x)
                {
                    secondClosest = thirdClosest;
                }
            }

            if (camera.WorldToViewportPoint(firstClosest).x >= camera.WorldToViewportPoint(secondClosest).x)
            {
                originalLeft = secondClosest;
                originalRight = firstClosest;
            }
            else
            {
                originalLeft = firstClosest;
                originalRight = secondClosest;
            }

            mostLeft = camera.WorldToViewportPoint(originalLeft);
            mostRight = camera.WorldToViewportPoint(originalRight);

            //Debug.Log("weird");
        }
        //TODO fix bug with the viewpoint switching and the code below is not correct anymore somehow

        //Debug.Log(camera.ViewportToScreenPoint(mostRight));
        //Debug.Log("left" + camera.ViewportToScreenPoint(mostLeft));

        if (mostLeft.x <= 0)
        {
            mostLeft.x = 0;
        }
        else if (mostLeft.x >= 1)
        {
            mostLeft.x = 1;
        }

        if (mostRight.x <= 0)
        {
            mostRight.x = 0;
        }
        else if (mostRight.x >= 1)
        {
            mostRight.x = 1;
        }

        Debug.DrawLine(originalLeft, objBounds.center, Color.blue, 0.5f);
        Debug.DrawLine(originalRight, objBounds.center, Color.red, 0.5f);

        //Debug.Log(camera.pixelRect);

        float width = camera.ViewportToScreenPoint(mostRight).x - camera.ViewportToScreenPoint(mostLeft).x;
        //Debug.Log(width);
        rightestViewPoint = camera.ViewportToScreenPoint(mostRight);
        return width;  //Total width can be gotten with pixelwidth of camera.

        // also return x and y from center point of visible points!
        //maybe also inform of pixel rect
    }
开发者ID:Darkfafi,项目名称:Summer_Game_Dev_2015_GameJam,代码行数:101,代码来源:RendererExtensions.cs

示例7: GetPerspectiveHeigth

    public static float GetPerspectiveHeigth(Collider objectCollider, Camera camera, out Vector3 highestViewPoint)
    {
        Bounds objBounds = objectCollider.bounds;

        float adjustValue = 1;
        float xNeg = objBounds.center.x - (objBounds.extents.x * adjustValue);
        float xPos = objBounds.center.x + (objBounds.extents.x * adjustValue);
        float yNeg = objBounds.center.y - (objBounds.extents.y * adjustValue);
        float yPos = objBounds.center.y + (objBounds.extents.y * adjustValue);
        float zNeg = objBounds.center.z - (objBounds.extents.z * adjustValue);
        float zPos = objBounds.center.z + (objBounds.extents.z * adjustValue);

        //List all different coordinates of the cube vertexes
        List<Vector3> cornerCoordinates = new List<Vector3>();
        List<Vector3> viewPortCornerCoordinates = new List<Vector3>();
        for (int x = 0; x < 2; x++)
        {
            for (int y = 0; y < 2; y++)
            {
                for (int z = 0; z < 2; z++)
                {
                    Vector3 coor = new Vector3();
                    coor.x = (x == 0) ? xNeg : xPos;
                    coor.y = (y == 0) ? yNeg : yPos;
                    coor.z = (z == 0) ? zNeg : zPos;
                    cornerCoordinates.Add(coor);
                    viewPortCornerCoordinates.Add(camera.WorldToViewportPoint(coor));
                }
            }
        }

        Vector3 highestPoint = new Vector3(float.MinValue, float.MinValue, float.MinValue);
        Vector3 lowestPoint = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

        foreach (Vector3 vpCoor in viewPortCornerCoordinates)
        {
            if (vpCoor.y >= highestPoint.y)
            {
                highestPoint = vpCoor;
            }
            else if(vpCoor.y <= lowestPoint.y)
            {
                lowestPoint = vpCoor;
            }
        }

        if (highestPoint.y >= 1)
        {
            highestPoint.y = 1;
        }

        if (lowestPoint.y <= 0)
        {
            lowestPoint.y = 0;
        }
        //Debug.Log("lowest" + lowestPoint);
        float height = camera.ViewportToScreenPoint(highestPoint).y - camera.ViewportToScreenPoint(lowestPoint).y;
        //Debug.Log("heigth" + height);

        highestViewPoint = camera.ViewportToScreenPoint(highestPoint);
        return height;
    }
开发者ID:Darkfafi,项目名称:Summer_Game_Dev_2015_GameJam,代码行数:62,代码来源:RendererExtensions.cs


注:本文中的UnityEngine.Camera.ViewportToScreenPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。