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 Radivarig · Oct 09, 2014 at 02:42 AM · guieditorwindowguilayoutguiwindow

GUI.Window called 2 frames ahead than OnGUI?

When modifying window rect for same amount before and after gui.window call:

 Vector2 mousePosition = Event.current.mousePosition;
 rect.position -= mousePosition;
 rect = GUILayout.Window (0, rect, DrawWindow, "bla");
 rect.position += mousePosition;

rect is not drawn properly in GUILayout.Window or GUI.Window, it moves as if I was feeding -Event.current.delta/2f to it (and if I add it back it stays still but looks glithy, so I have to round values which is a mess).

Seems to me like gui.window is called frame after even tho if I drag the window, rect before will not be the same as rect after inside the scope which is expected.

So, rect.position before addition and after subtraction is same, but rect is not drawn where it should be in gui.window, it moves dependently of mousePosition since that value is changing between frames.

I have stored the mouse position of second last frame and it works but it makes a lot of new problems that are hard to track. How can this be done without assigning past values?

Thanks!

Comment
Add comment · Show 4
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 unimechanic ♦♦ · Oct 09, 2014 at 02:34 PM 0
Share

What are you trying to achieve in the end? Dragging or resizing the window?

avatar image Radivarig · Oct 09, 2014 at 02:42 PM 0
Share

I implemented offset and scaling, but the values jump like crazy while its visually ok. I'd like to understand what is happening so I can write clean code.

avatar image Radivarig · Oct 10, 2014 at 02:25 PM 0
Share

gentle bump

avatar image troien · Oct 15, 2014 at 03:15 PM 0
Share

Not sure if this helps anything, but maybe you could try something like this? Because this is currently executed at least 2 times per frame, and maybe more depending on mousemove, keypress etc. (If this doesn't help then I don't know what the problem could be :p)

         if (Event.current.type == EventType.Layout)
         {
             rect.position -= mousePosition;
         }
         rect = GUILayout.Window(0, rect, DrawWindow, "bla");
         if (Event.current.type == EventType.Layout)
         {
             rect.position += mousePosition;
         }

0 Replies

· Add your reply
  • Sort: 

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

30 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

Related Questions

GUILayout three buttons alligned horizontally with no spaces between them 1 Answer

rotate a single GUI element around pivotPoint 0 Answers

Get Mouse Events with EditorWindow 3 Answers

How do i get size in pixels of a GUI.Label for chat construction purpose ? 2 Answers

Can not close editor window not in GUILayout.somemethod in OnGUI method 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