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 alexanderameye · Nov 03, 2015 at 12:03 PM · guieditoreditor-scriptingstringhierarchy

Hierarchy in editor

I have a public string so it shows up in the editor, but how could I make it so that this string shows up under a menu, so for example:

 > Menu
    String

So the public string only shows up in the editor when I actually click on the black arrow next to the menu. Just like how the hierarchy works with parents and children. So I want the public string to be a child the menu 'folder'

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
1
Best Answer

Answer by ThomasVandenberghe · Nov 03, 2015 at 01:17 PM

You can use

 [Header("Menu")]
 public int myInt = 0;

This can be used to group variables together, but you won't be able to collapse the data.

Here's the unity link for reference http://docs.unity3d.com/ScriptReference/HeaderAttribute.html

You can also use

 [Space(10)]

If you want some extra space between variables

Comment
Add comment · Show 1 · 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 alexanderameye · Nov 03, 2015 at 03:23 PM 0
Share

Tyvm! This is an easy solution and grouping the variables was indeed what I wanted! Thank you for your answer!

avatar image
2

Answer by Bunny83 · Nov 03, 2015 at 12:27 PM

The inspector is there to simply allow editing of the variables of an instance. There's no built-in functionality to somehow group member variables inside a class logically. However you can physically group several variables in a seperate serializable class.

 // C#
 [System.Serializable]
 public class SomeData
 {
     public string someString;
     public int someInt;
 }
 
 public class MyMonoBehaviour : MonoBehaviour
 {
     public SomeData data;
 }


That way your class MonoBehaviour will show a field "data" which can be expanded.

You can also nest classes to create a hierarchy. It's also possible to make an array or List of a custom class. Just try it out.

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 alexanderameye · Nov 03, 2015 at 03:22 PM 0
Share

Thanks, I'm not very familiar with GUI's or editor scripting so I think I'll just use the other guy's answer. Your answer does motivates me to take a good in-depth look at editor scripting, tyvm for your fast answer!

avatar image Bunny83 alexanderameye · Nov 03, 2015 at 03:52 PM 0
Share

Use whatever you like ^^. I always forget about the (relatively new) Header attribute, probably because i never use it. It just makes the variable listing longer. In some cases it might be quite handy.

You don't need any editor scripting for what i said in my answer ^^. The above example will directly give you what you want. Even some of Unity's standard assets use this approach (the FPS controller as far as i remember).

In the inspector you will see a "data" foldout which can be collapsed / expanded. When expanded you will see the two members inside the "child" class.

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

46 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 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

Trigger an event from editor script? 0 Answers

Editor Control Automagically "Filling" in Data 1 Answer

Issue with custom editor window zooming feature 0 Answers

Unity Editor How to Detect a Change of a Specific Component Field 1 Answer

ShaderGraph-like EditorWindow 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