// ... void OnGUI() { Meta2dBounds tmp2dBounds = Tank.GetComponent <GameObjectBoundaries> ().GetScreenSpaceBounds(true); float coverage = tmp2dBounds.GetScreenCoverage(); string visibility = tmp2dBounds.GetVisibility().ToString(); GUI.skin.box.alignment = TextAnchor.MiddleLeft; GUI.Box(new Rect(0, 0, 256f, 48f), "Tank Screen Coverage = " + coverage.ToString() + "\n" + "Tank Visibility = " + visibility); }
// ================================================================================================================================ /// <summary> /// Get screen space boundaries. /// </summary> public Meta2dBounds GetScreenSpaceBounds(bool ParamRecalculate) { Vector3[] tmpCorners = GetCornersFromBounds(GetBounds(ParamRecalculate)).ToArray(); float maxX = CurrentCamera.WorldToScreenPoint(tmpCorners[0]).x; float maxY = CurrentCamera.WorldToScreenPoint(tmpCorners[0]).y; float minX = CurrentCamera.WorldToScreenPoint(tmpCorners[0]).x; float minY = CurrentCamera.WorldToScreenPoint(tmpCorners[0]).y; float minZ = CurrentCamera.WorldToScreenPoint(tmpCorners [0]).z; // Lowest Z will determine if object is behinf camera int i; for (i = 1; i < tmpCorners.Length; i++) { Vector3 tmpVec = CurrentCamera.WorldToScreenPoint(tmpCorners[i]); if (tmpVec.x > maxX) { maxX = tmpVec.x; } if (tmpVec.x < minX) { minX = tmpVec.x; } if (tmpVec.y > maxY) { maxY = tmpVec.y; } if (tmpVec.y < minY) { minY = tmpVec.y; } if (tmpVec.z < minZ) { minZ = tmpVec.z; } } Meta2dBounds tmp2dBounds = new Meta2dBounds(); tmp2dBounds.topLeft = new Vector3(minX, maxY, minZ); tmp2dBounds.topRight = new Vector3(maxX, maxY, minZ); tmp2dBounds.bottomRight = new Vector3(maxX, minY, minZ); tmp2dBounds.bottomLeft = new Vector3(minX, minY, minZ); return(tmp2dBounds); }
// =================================== void OnGUI() { if (DrawScreenSpaceBounds) { Meta2dBounds tmp2dBounds = GetScreenSpaceBounds(true); Meta2dBounds.Meta2dBoundsVisibility tmpVisibility = tmp2dBounds.GetVisibility(); if (tmpVisibility == Meta2dBounds.Meta2dBoundsVisibility.Full || tmpVisibility == Meta2dBounds.Meta2dBoundsVisibility.Partial) { float x = tmp2dBounds.topLeft.x; float y = tmp2dBounds.topLeft.y; float width = tmp2dBounds.GetWidth(); float height = tmp2dBounds.GetHeight(); DrawQuadOnScreen(new Rect(x, Screen.height - y, width, height)); } } }