Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DaveA · Jun 23, 2011 at 10:19 PM · windowguilayoutresize

Problem resizing a GUILayout window

I'm in need of resizing a GUILayout-based window (for mobile). Basically the user can choose small/medium/large UI depending on their device's needs. (I change font and some other element sizes). The window needs to auto-calculate itself to fit itself to the new sizes.

I've been doing this by setting the window rect to something small (like 20x20) so that the next OnGUI will recalculate it. Which it does. Now the problem:

For one frame, I get a small window. The next frame repaints with a nice window size, but this flash is pretty annoying.

What's the best way to tell a GUILayout window to recalculate itself without getting this type of flash?

Comment
Add comment · Show 1
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 AlanChatham · Jun 23, 2011 at 11:41 PM 0
Share

It sounds like you're drawing your 20x20 rectangle in the first frame, then it resizes in the next and subsequent frames. Is that correct? You might try something that automatically calculates the size on the first frame, or start with a 0x0 window... Do you have a bit of your OnGUI()/rectangle initialization code you can share?

1 Reply

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

Answer by Waz · Jun 24, 2011 at 12:25 AM

This sounds like the sort of problem you get if you change the layout size during layout events. IIRC, you should only make such a change in the Repaint phase (the last phase):

 if (GUILayout.Button("Big")) newSize = Size.Big;
 ...
 if(Event.current.type == EventType.Repaint && newSize != Size.Unchanged) {
    switch (newSize) {
        case Size.Big: uiWidth = 100; ...
    }
 }

May be best to post a summary of your code though.

Comment
Add comment · Show 2 · 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 DaveA · Jun 24, 2011 at 12:51 AM 0
Share

Thanks. I knew there was something about a repaint phase somewhere but forgot where it was in the docs. I'll try that. Although, reading the EventType for Layout, sounds like that IS where I'd want to do this? I'll try.

avatar image DaveA · Jun 24, 2011 at 01:04 AM 0
Share

Yeah actually it works better if I reset the size during the Layout event, not the Repaint. But you led me to it, cheers!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Force aspect ratio of window (standalone Windows) 1 Answer

Windows that do not take priority over other GUI elements 0 Answers

4.6 UI : How to automatically set the size of a pannel from the size of inner text or other elements 1 Answer

GUI Window Render Priority 1 Answer

Margin not working on UILayout.BeginVertical("Window") 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