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
4
Question by MiguelDeLaCruz · May 04, 2011 at 05:45 PM · editoreditorwindowdockdocked

Is there an EditorWindow is docked value?

Hi, I'd like to figure out if the EditorWindow has an undocumented value or function that lets me know if it is docked or not. The reason I need it is because when I try to resize the window via script, it undocks it, so if I could check for that to not resize it, that would be great!

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
6

Answer by stevethorne · Dec 11, 2013 at 05:01 PM

I know this is very late but there are probably more people looking for this answer. There is a solution! Unfortunately it isn't a public variable, so you'll have to use some fancy workarounds to do it. Here's what I use to get the "docked" variable from an EditorWindow.

 BindingFlags fullBinding = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
 
 MethodInfo isDockedMethod = typeof( EditorWindow ).GetProperty( "docked", fullBinding ).GetGetMethod( true );
 
 if ( ( bool ) isDockedMethod.Invoke(this, null) == false ) // if not docked
     m_This.position = new Rect( 40, 40, Screen.currentResolution.width / 3, Screen.currentResolution.height / 4 * 3 );

What's going on here?

The first line with BindingFlags sets up the binding for our Method info to allow us to get any variable from EditorWindow, whether it is an instance variable, static variable, public variable, or non-public variable.

The if statement contains a lot in it but I'll break it down here.

 MethodInfo isDockedMethod = typeof( EditorWindow ).GetProperty( "docked", fullBinding ).GetGetMethod( true );

This gives us a MethodInfo which allows us to call a function or get a variable based on a string. We're getting a MethodInfo for a property called "docked" that follows our BindingFlags for a class called EditorWindow. This MethodInfo is kind of useless on its own, though. So we need to invoke this MethodInfo on an object, and that object is "this".

 if ( ( bool ) isDockedMethod.Invoke(this, null) == false )

This part invokes the MethodInfo on "this" and checks if the variable "docking" is set to false.

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 Akzwar · Nov 16, 2020 at 10:15 PM

One can insert this in class inherited from EditorWindow

 public bool IsDocked
 {
     get
     {
         BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance;
         MethodInfo method = GetType().GetProperty( "docked", flags ).GetGetMethod( true );
         return (bool)method.Invoke( this, null );
     }
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity Editor Event System 1 Answer

Changes to Object made in custom Editor Window don't persist 0 Answers

Keep equal width for panels in EditorGUILayout.HorizontalScope 0 Answers

Execute editor window scripts when project errors are present 0 Answers

Is interraction between EditorWindow and php file possible? 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