Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
1
Question by JoVirtual · Sep 14, 2021 at 04:29 AM · 2d gameviewport

Is unity able to do what I need?

Heyo. Hopefully this question is in the right place. If not, please move it, because I seriously need help with this. Thanks!

So I got working on a new project that was migrated over from plain C++ to Unity, since this engine is doing everything I needed (except one major thing), and development time is so much better compared to my C++ project. But, with the C++ project, I could do what I needed quite easily with a call to a function named "glViewport()." But with Unity, I'm not sure how I could do this, other than put two random quads above and below my "game area" (and this would seem to me to be a nasty hack that I would like to avoid at al costs...if at all possible...), so I'm asking to get some feedback on whether this engine can do what I need.

Based on my designs, my game needs to have two black bars above and below the "viewport" of the game. I really, really need this to happen, because of the UI I have planned, and the general gameplay depends heavily on this requirement. Failing to meet this requirement would mean redesigning what I had previously come up with.

Here is what I'm talking about: I draw up this picture to describe what I mentioned.

alt text

So, even if the window is resized, the game should retain this style of viewport, so it's not anythign to do with aspect ratio "black bars" like other people have asked about.

Does anyone know how this could be done without the two quads hack? Is frustum culling useful for my game's needs? If so, how? This would be the first time I've ever used frustum culling, so I would need to do a lot of research on this, including trial and error, so if anyone has anything on that, I would appreciate it hugely. Or, is there anything in Unity that mimics what "glViewport()" would do in OpenGL?

screendemo1.png (6.5 kB)
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

Answer by Bunny83 · Sep 14, 2021 at 07:59 AM

You can set the viewport of a camera by changing its viewport rect in the inspector. Though this viewport rect is in normalized coordinates. So the offset and height / width is essentially given in "percentage" (0 - 1) of the entire screen. If you want a fix pixel offset, you have to recalculate it from the screen size whenever the window is resized. Note that (0,0) is the bottom left corner while (1,1) is the top right corner.

Since you seem to want an offset from the bottom and an offset from the top, you have to increase the Y offset according to your wanted pixel count and the height (H) of the viewport by twice that amount.


Of course if you actually want a percentage, you could just set the values in the inspector once and it will keep that percentage. Though according to your image you want a fix pixel offset.


Unity also has the pixelRect property which should be the pixel equivalent of the viewport size. Though you still would need to set it when the size changes.

Comment
Add comment · Show 1 · 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 Pangamini · Sep 14, 2021 at 09:50 AM 0
Share

It should be possible to use canvas and layout classes for convenience, then read back the actual screenspace rect of a particular rectTransform and apply that to the camera viewport

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

170 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity2D Action when object close to Camera 0 Answers

left and right buttons for android 2d game 1 Answer

Android Game screen resolution 2 Answers

water changing color of player 2d 0 Answers

Brick Breaker - Ball not bouncing back from the brick. 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