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 Tumtable · Jan 09, 2015 at 07:11 PM · uieditor-scriptingeditorguilayoutcustom-editoreditor-classes

Who create a group on a custom Editor like a class group?

When you creates a class on a script, the variables appears on the editor inside a group that can be maximized an minimized. How can I create this on a custom editor?

Like this, for example:

alt text

screenshot_1.png (18.5 kB)
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
3
Best Answer

Answer by vexe · Jan 09, 2015 at 07:47 PM

It's just a foldout, and indented fields. Something like this should work:

 foldout = EditorGUILayout.Foldout(foldout, "Network whatever");
 if (foldout) 
 {
    var level = EditorGUI.indentLevel;
    EditorGUI.indentLevel++;
    // ... whatever fields you want
    EditorGUI.indentLevel = level;
 }


'foldout' is a boolean you define somewhere in your editor script


EDIT (BONUS): Since we mentioned indentation, if you write a lot of editor codes, you might want to make a GUI library that makes things a bit more convenient/easy to use/faster to type. For example, it is very common to increase indentation and then revert it back, same thing for GUI.color and EditorGUILayout.labelWidth, GUI.changed, and some others. Another thing is the "blocks" so you have a BeginHorizontal and a corresponding EndHorizontal. One might find that a lot to type, and you also have to remember to insert an Ending. So can we do something to limit mistakes and reduce typing?

Sure, 'using' and IDisposable are your friends!

 public class GUIColorBlock : IDisposable
 {
     private Color prevColor;

     public GUIColorBlock Begin(Color newColor)
     {
         prevColor = GUI.color;
         GUI.color = newColor;
         return this;
     }

     public void Dispose()
     {
         GUI.color = prevColor;
     }
 }

 public static class gLib // for GUILibrary
 {
     private static GUIColorBlock colorBlock = new GUIColorBlock();
 
     public static GUIColorBlock ColorBlock(Color c)
     {
        return colorBlock.Begin(c);
     }
 }

Then in your editor scripts, instead of doing:

 var old = GUI.color;
 GUI.color = newColor;
 // some gui controls
 GUI.color = old;

you can now say:

 using (gLib.ColorBlock(newColor))
 {
    // your gui controls!
 }

When the scope of the using statement ends, 'Dispose' gets called and the colors gets back to the previous value! - obviously you can follow similar patterns to indentation, begin/end blocks etc.

(lookup 'using' and IDisposable if you're unfamiliar with them)

And if you like writing GUI code like, check out RabbitGUI, my custom layout system in VFW :)

Hope that helps!

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 Tumtable · Jan 09, 2015 at 10:45 PM 0
Share

Thank you =]

avatar image vexe · Jan 09, 2015 at 11:07 PM 0
Share

@Trumtable, see my update, added some bonus :p why? cause I feel like it

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

26 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

Related Questions

Track when the value is changed and get it 0 Answers

Unity UI 4.6 - Programmatically adding events - EventTrigger.delegates is null 0 Answers

Editor window script only works when window is open? 1 Answer

Create a custom editor window with repeating subsection (mockup included) 0 Answers

Is it possible to store and display EditorGUILayout.Toggles? 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