Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ikelaiah · Sep 03, 2013 at 11:38 PM · linerendererviewportlinesbordervectrosity

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:

  1. 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.

  2. 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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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;
 }
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Sajidfarooq · Sep 03, 2013 at 11:45 PM 1
Share

$$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...

avatar image ikelaiah Sajidfarooq · Sep 04, 2013 at 02:26 AM 0
Share

Trying (B) now...

avatar image Eric5h5 Sajidfarooq · Sep 04, 2013 at 03:10 AM 1
Share

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.

avatar image Eric5h5 Sajidfarooq · Sep 04, 2013 at 06:20 AM 1
Share

Well, you can fix that part by using the left/right/top/bottom border properties.

Show more comments
avatar image ikelaiah · Sep 04, 2013 at 03:40 AM 0
Share

Thanks. I was able to follow your algorithm clearly.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges