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 deathbane · May 07, 2014 at 12:13 AM · guieditoreditor-scriptingcustom-inspector

What is a GUILayoutOption[]

I am trying to write an editor script but I don't know what a GUILayoutOption[] is, and what to feed the parameter.

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

3 Replies

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

Answer by Bunny83 · May 07, 2014 at 12:54 AM

The optional "options" array of all GUILayout controls allows you to override certain aspects of the layout behaviour. It is a "params" array which always has to be the last parameter of a method. Possible "values" you can feed to a control are generated by those methods:

  • GUILayout.Width - overrides the fixedWidth of the used style

  • GUILayout.Height - overrides the fixedHeight of the used style

  • GUILayout.MaxHeight - adds an additional size-constraint

  • GUILayout.MaxWidth - adds an additional size-constraint

  • GUILayout.MinHeight - adds an additional size-constraint

  • GUILayout.MinWidth - adds an additional size-constraint

  • GUILayout.ExpandWidth - overrides stretchWidth of the used style

  • GUILayout.ExpandHeight - overrides stretchHeight of the used style

You can either setup an array yourself, add any of the above mentioned "values" and pass the array to the control, or, which is the actual intended usage, just pass the desired options as "additional parameters" like this:

  if (GUILayout.Button("Button Text", GUILayout.MinWidth(100),GUILayout.Width(30)))

The "params" keyword allows to pass the array members as optional parameters. That's why it has to be the last parameter. All additional parameters become an item in the options array. If you don't need / want to override the GUIStyles behaviour, don't pass anything:

  if (GUILayout.Button("Button Text"))


Comment
Add comment · Show 3 · 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 deathbane · May 07, 2014 at 12:58 AM 0
Share

What if I wanted to change position? or even relative position?

avatar image Bunny83 · May 07, 2014 at 01:09 AM 0
Share

It's not possible to change the position directly since GUILayout elements are layouted automatically. You can use GUILayout.Space to add empty spaces between elements, but usually you should setup the margins of you GUIStyle to affect it's position. I strongly recommend to use your own custom GUISkin if you don't use one yet.

You might also want to take a look at my generic Unity GUI crashcourse in **this answer**

avatar image Bunny83 · May 07, 2014 at 01:11 AM 1
Share

The great thing with the GUISkin is you can change it at runtime while testing and it will keep the changes(so watch out what you change). This allows you to tweak the values / settings of your styles which the GUI is rendered and you immediately see the result.

avatar image
1

Answer by toomasio · Jun 18, 2018 at 05:18 PM

You can create your own layout options in a stored variable if you want to use the same ones repeatedly. eg:

 private GUILayoutOption[] textAreaOptions;
 
     public void OnEnable()
     {
         textAreaOptions = new GUILayoutOption[]
         {
             GUILayout.Height(48),
             //add more layout options
         };
     }
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 Jeff-Kesselman · May 07, 2014 at 12:58 AM

It is an array of objects of type GUILayoutOption.

for instance:

 windowRect = GUILayout.Window(0, windowRect, ScalingWindow, "resizeable", GUILayout.MinWidth(80), GUILayout.MaxWidth(200));

GUILayout.MinWidth(...) and GUILayout.MaxWdth(...) are the GUILayoutOptions

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

24 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

Related Questions

Custom Editor GUI Elements 1 Answer

Issues with AnimationCurves 0 Answers

How can i get SerializedProperty from UnityEvent which in List. Sorry for my Eng. 2 Answers

TexturePropertySingleLine in Editor class 0 Answers

Get default preview for GameObject Editor 2 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