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 chrispug · Feb 23, 2021 at 05:06 AM · inspectorformatformatting

Editing how bools appear in the Inspector

If I have a series of booleans, in this case 9, is there a way to format them inside of the inspector for quality of life purposes?

For example: alt text

Turning ^this, into this - alt text

These are just examples, of course. It's a relatively small thing, but when setting up a system for people of various skill/experience levels to be working with, having the inspector set up like this would certainly make processes much easier, as it's significantly more intuitive.

Is this possible? I've never really considered modifying the inspector before.

bools.png (31.1 kB)
screenshot-2021-02-22-235417.png (21.7 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
0
Best Answer

Answer by Namey5 · Feb 23, 2021 at 06:18 AM

You could do this fairly easily with a custom editor, however if this was something that occurs in numerous scripts I would suggest putting all spaces into a single object and creating a custom PropertyDrawer, something along the lines of;

 [System.Serializable]
 public struct Spaces
 {
     public bool space1;
     public bool space2;
     public bool space3;
     public bool space4;
     public bool space5;
     public bool space6;
     public bool space7;
     public bool space8;
     public bool space9;
 }
 
 ...
 
 using UnityEditor;
 
 [CustomPropertyDrawer (typeof (Spaces))]
 public class SpacesDrawer : PropertyDrawer
 {
     public override void OnGUI (Rect a_Rect, SerializedProperty a_Property, GUIContent a_Label)
     {
         //Shorthand to make writing easier
         float lh = EditorGUIUtility.singleLineHeight;
 
         //Draw our label in the full rect (will self centre) but leave room at the end for the bools
         Rect labelRect = new Rect (a_Rect.x, a_Rect.y, a_Rect.width - lh * 3f, a_Rect.height);
         EditorGUI.LabelField (labelRect, a_Label);
 
         //This is where the bools will start on the x-axis
         float boolStartX = a_Rect.x + labelRect.width;
         //Initialise the bool rect to the top-left corner (1 line wide and tall)
         Rect boolRect = new Rect (boolStartX, a_Rect.y, lh, lh);
         //We want the bools to go left -> right then top -> bottom, so start with the y-axis as the outside loop
         for (int y = 0; y < 3; y++)
         {
             //Re-initialise the x-axis with every new row
             boolRect.x = boolStartX;
             for (int x = 0; x < 3; x++)
             {
                 //Find the current index (starting at 1)
                 int currentBool = x + y * 3 + 1;
                 //Draw the bool as normal (without a label)
                 EditorGUI.PropertyField (boolRect, a_Property.FindPropertyRelative ("space" + currentBool), GUIContent.none);
                 //Move to the next bool in the row
                 boolRect.x += boolRect.height;
             }
             //Move to the next row of bools
             boolRect.y += boolRect.width;
         }
     }
 
     //We need to override the property height - let's make it 3 lines (a regular property will be 1 line high)
     public override float GetPropertyHeight (SerializedProperty a_Property, GUIContent a_Label)
     {
         return EditorGUIUtility.singleLineHeight * 3f;
     }
 }
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 chrispug · Feb 23, 2021 at 06:20 AM 0
Share

Awesome! Thank you, going to try this as soon as I can.

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

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

Alternative for the True Color Option - Format 2 Answers

I cant fix format truecolor. it not show.,I cant fix format true color. it not show. 0 Answers

How to apply code formatting, in a Numbered/Bulleted list? 2 Answers

Adding variables to inspector strings 1 Answer

Export objects to a .3DS file at runtime 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