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
2
Question by swisscoder · Feb 10, 2012 at 06:16 PM · editoreditor-scriptingeditorgui

Size of the header of the EditorWindow

Hi there,

I just realized, that when I use Screen.height from within an editor window, it gives my not the actual space I have to draw the things inside.

The problem => the header bar is included as well in this calculation for the height!

I measured it to be around 22 pixels, on a Window 7 / Unity Pro setup. Probably this value differs with other setting?

Is there a constant or something that gives back that value?

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 SteveFSP · Feb 11, 2012 at 09:03 PM

To get the draw area of an editor Window, use EditorWindow.position. Don't be fooled by the name. It's a Rect that indicates the draw area.

Edit: Added some example code.

// C# - The OnGUI() function in the EditorWindow. void OnGUI() { Rect drawArea = position; // EditorWindow.position

 // Detecting the mouse inside the window.

 Event evt = Event.current;
 Vector2 mousePos = evt.mousePosition;

 if (drawArea.Contains(mousePos))
 {
     // Mouse is inside the draw area.

     if (evt.type == EventType.MouseDown && evt.button == 0)
     {
         // Clicked...
     }
 }

 // Draw a red rectangle that fills half of the draw area.
 // (From the draw origin.)

 Vector3[] cellVerts = new Vector3[4];

 Vector3 origin = new Vector3(drawArea.x, drawArea.y);

 cellVerts[0] = origin;

 cellVerts[1] = origin;
 cellVerts[1].x += drawArea.width / 2;

 cellVerts[2] = origin;
 cellVerts[2].x += drawArea.width / 2;
 cellVerts[2].y += drawArea.height / 2;

 cellVerts[3] = origin;
 cellVerts[3].y += drawArea.height / 2;

 Handles.DrawSolidRectangleWithOutline(cellVerts, Color.clear, Color.red);

}

Comment
Add comment · Show 4 · 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 swisscoder · Feb 12, 2012 at 04:07 PM 0
Share

Great. But to calculate weather or not the mouse is inside this Rect, I still need to know how big the offset is.

avatar image swisscoder · Feb 12, 2012 at 04:41 PM 0
Share

Actually this does not work! EditorWindow.position does give back the size of the total EditorWindow! EditorWindow.position.height = screen.Size +1

This does definitely not take the offset for the title bar into account.

avatar image SteveFSP · Feb 12, 2012 at 05:29 PM 1
Share

If it doesn't work, then my rather complex EditorWindow implementation must be working by magic. :-) I've added some example code derived from my own implementation. I've never had to adjust the position Rect take the tile bar into account.

avatar image swisscoder · Feb 12, 2012 at 06:28 PM 0
Share

Hmm, you are right! What a shame, I probably read 60 as 80, else I can not explain it. Now I had the following results:

Clicked at: (274.0, 6.0) - Was 6 Pixel below the title bar => correct drawArea: (left:314.00, top:197.00, width:952.00, height:463.00) Screen.height: 485

Height is 22 Pixel smaller => correct!

$$anonymous$$aybe work on sunday made me missinterpret it ;) Thank you a lot Steve!!!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Editor Window Views 0 Answers

Print to status bar. 0 Answers

SceneView.onSceneGUIDelegate GUI sorting problem 1 Answer

Lining up GUI 1 Answer

Where can I find advanced controls for custom editor? 1 Answer


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