- Home /
What is the best way to draw a border around a viewport?
I have a small viewport, and I would like to know what is the best way to draw a line or border around the viewport.
I tried the following:
I used line renderer and specify the points in 3D. This approach is tedious as I have to specify the x, y, z coordinates to make a rectangle in a way to frame the viewport.
I used Line.MakeRect() method from Vectrosity. It works great. Except that when scaling (switching from 4:3 to 16:9 aspect ratio) occurs, it does not scale but retains position. Which is great, but not desirable as viewport get scaled when aspect ratio changes.
So my question is,
what is the best way to draw a border around viewport? In a way so that it always matches with the scaling effect.
Answer by Eric5h5 · Sep 04, 2013 at 03:06 AM
Using Vectrosity, redraw the border if the resolution changes:
import Vectrosity;
private var border : VectorLine;
var borderWidth = 4;
private var screenWidth : int;
function Start () {
border = new VectorLine("border", new Vector2[5], null, borderWidth, LineType.Continuous, Joins.Weld);
UpdateBorder();
}
function Update () {
if (Screen.width != screenWidth) {
UpdateBorder();
}
}
function UpdateBorder () {
VectorLine.SetCamera();
border.MakeRect (Vector2(borderWidth/2, borderWidth/2),
Vector2(Screen.width-borderWidth/2, Screen.height-borderWidth/2));
border.Draw();
screenWidth = Screen.width;
}
$$anonymous$$any ways to do this.
a) Simplest: Create a GUITexture with an image of a transparent box (just borders). It will scale correctly with viewport changes if you set all "Pixel inset" values to 0, and set scale (x,y and z) to 1.
b) Update the values of "rect" based on Screen.width and Screen.height (or viewport respectively).
Use UnityGUI/Vectrosity to draw the lines in 2d with respect to your viewport size.
Im sure I am missing some still...
a) is definitely simplest, however it's a big shame to cover the entire screen with a transparent texture when you will only be using 1% of it...big waste of fill-rate.
Well, you can fix that part by using the left/right/top/bottom border properties.
Your answer
Follow this Question
Related Questions
3D ellipse with Vectrosity 1 Answer
[Not Solved]Line renderer ugly lines, how to fix? 1 Answer
Geometry shader for thick lines in clip space 2 Answers
Rendering large amount of lines 2 Answers
Collider is not working... 2 Answers