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 Mister-E · Jul 08, 2012 at 10:23 AM · cameragraphicsdrawtexture

Graphics.DrawTexture() on 1 camera

Hi, I am trying to create some nice gui for my game. I have a split screen setup going on and I have come to some problem. Using GUITextures, I was able to draw only on the camera I choose, by that I mean, I could create a GUIGroup that has the dimensions of each camera, and use that to draw my GUI on both screens. The problem is that Graphics.DrawTexture doesn't seem to have that functionality(as far as I can see), can anyone guide me on the best way to achieve this?

p.s. I switched to Graphics.DrawTexture so I could use the source Rectangle paramater to do 2d animations on my gui.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ScroodgeM · Jul 27, 2012 at 12:55 PM

GUI. and Graphics. draws not to camera, but to screen. you can draw texture even without any camera, so you are not able to control graphics.drawtexture draws by switching cameras

Comment
Add comment · 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
0

Answer by Bunny83 · Jul 27, 2012 at 01:22 PM

I guess you could use one of the camera event to bind the texture drawing to a certain camera and to distinguish which one is rendering. See Camera.current and the mentioned events, especially OnRenderObject. This event is called for each camera. You have to setup the viewport yourself in this case.

Another way, probably the better, is to use OnGUI and setup two GUIs for each view. Keep in mind that there is the GUIUtility class which has some functions to convert between gui and screen space. Those functions take GUI.Groups into account.

edit

When using GUILayout you can use GUILayoutUtility.GetRect to reserve an area for the drawtexture call. The rects origin has to be converted into screen-space of course (GUIToScreenPoint) ;)

I almost exclusively use GUILayout since it arranges itself and you can still specify fix heights / widths for certain elements.

//C# void OnGUI() { GUILayout.BeginArea(new Rect(0,0,Screen.width,Screen.height)); GUILayout.BeginHorizontal();

 GUILayout.BeginVertical();
 // Left GUI here
 GUILayout.EndVertical();
 
 GUILayout.BeginVertical();
 // Right GUI here
 GUILayout.EndVertical();
 
 GUILayout.EndHorizontal();
 GUILayout.EndArea();

}

If the GUI is exactly the same for both sides, i would use a function that takes a context as parameter

 void PlayerGUI(PlayerContext player)
 {
     Rect myTexRect = GUILayoutUtility.GetRect(100,50);
     
     // GUI here
     
     if (Event.current.type == EventType.Repaint)
     {
         Vector2 tmp = GUIUtility.GUIToScreenPoint(new Vector2(myTexRect.x, myTexRect.y));
         myTexRect.x = tmp.x;
         myTexRect.y = tmp.y;
         Graphics.DrawTexture(myTexRect, /* ... */);
     }

 }

 //[...]
 GUILayout.BeginVertical();
 PlayerGUI(player1);
 GUILayout.EndVertical();
 
 GUILayout.BeginVertical();
 PlayerGUI(player2);
 GUILayout.EndVertical();
 //[...]



Comment
Add comment · 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

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

7 People are following this question.

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

Related Questions

Unsmooth camera on sprite diffuse 0 Answers

Graphics.DrawTexture vs GUI.DrawTexture vs Graphics.Blit 0 Answers

How does Unity handle alpha sorting? 2 Answers

Fading in one camera over another as an overlay with RenderTexture and GUI.DrawTexture. Any way to control pixel clearing? 0 Answers

Graphics.Blit or texture update how long to draw to entire screen? 0 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