本文整理汇总了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;
}
示例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;
}
示例3: ViewportToScreenY
public float ViewportToScreenY(Camera camera, float viewportY)
{
return camera.ViewportToScreenPoint(new Vector2(0, viewportY)).y;
}
示例4: ViewportToScreenX
public float ViewportToScreenX(Camera camera, float viewportX)
{
return camera.ViewportToScreenPoint(new Vector2(viewportX, 0)).x;
}
示例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);
}
示例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
}
示例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;
}