using UnityEngine;
using System.Collections;
public class DrawScreenSafeArea : MonoBehaviour
{
public bool drawScreenSafe = false;
public bool draw720p = false;
public float screenSafePercentage = 0.1f;
public int vertOffset = -100; // What is the offset of the UI in the world?
void OnDrawGizmos()
{
if (drawScreenSafe)
{
Gizmos.color = Color.green;
Vector3 parentScale = gameObject.transform.parent.localScale * 0.5f;
float xSize = 1280.0f * (1.0f - screenSafePercentage);
float ySize = 720.0f * (1.0f - screenSafePercentage);
Vector3 topLeft
= new Vector3
(-xSize
* parentScale
.x,
(ySize
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 topRight
= new Vector3
(xSize
* parentScale
.x,
(ySize
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 bottomLeft
= new Vector3
(-xSize
* parentScale
.x,
(-ySize
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 bottomRight
= new Vector3
(xSize
* parentScale
.x,
(-ySize
* parentScale
.y) + vertOffset, 0
.0f
);
Gizmos.DrawLine(topLeft, topRight);
Gizmos.DrawLine(topRight, bottomRight);
Gizmos.DrawLine(bottomRight, bottomLeft);
Gizmos.DrawLine(bottomLeft, topLeft);
//Vector3 origin = new Vector3(0.0f, 0.0f, 0.0f);
//Vector3 lineUp = new Vector3(0.0f * parentScale.x, 720.0f * parentScale.y, 0.0f);
//Gizmos.DrawLine(origin, lineUp);
}
if (draw720p)
{
Gizmos.color = Color.green;
Vector3 parentScale = gameObject.transform.parent.localScale * 0.5f;
Vector3 topLeft
= new Vector3
(-1280
.0f
* parentScale
.x,
(720
.0f
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 topRight
= new Vector3
(1280
.0f
* parentScale
.x,
(720
.0f
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 bottomLeft
= new Vector3
(-1280
.0f
* parentScale
.x,
(-720
.0f
* parentScale
.y) + vertOffset, 0
.0f
); Vector3 bottomRight
= new Vector3
(1280
.0f
* parentScale
.x,
(-720
.0f
* parentScale
.y) + vertOffset, 0
.0f
);
Gizmos.DrawLine(topLeft, topRight);
Gizmos.DrawLine(topRight, bottomRight);
Gizmos.DrawLine(bottomRight, bottomLeft);
Gizmos.DrawLine(bottomLeft, topLeft);
}
}
}