Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Multiple bools in one line in Inspector

Discussion in 'Scripting' started by Davitosan, May 10, 2013.

Thread Status:
Not open for further replies.
  1. Davitosan

    Davitosan

    Joined:
    May 10, 2013
    Posts:
    3
    I'm not sure how to ask this question or subsequently search for it. So, here is a picture.
    $class-Rigidbody-0.jpg

    In the Rigidbody component under Constraints the two fields have three Boolean check boxes on the same line.

    Is this a single data type? I would like to utilize it instead of making three separate bools.
    Is this something special that cannot be replicated?

    Thank you,
    David
     

    Attached Files:

  2. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,796
    That is most likely 3 booleans as it doesn't make sense to have a specific type with 3 boolean operators as it is so rarely used.
    I know you can get 3 text boxes by using a Vector type.

    You might want to check out the Unity Editor classes for more information though.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's an enum, based on an int. See here. They would have done something like "enum Constraints {FreezePositionX = 1, FreezePositionY = 2, FreezePositionZ = 4, etc." Then they would have written a PropertyDrawer for Constraints so that it's displayed like that.

    --Eric
     
    APSchmidtOfOld and Bunny83 like this.
  4. Davitosan

    Davitosan

    Joined:
    May 10, 2013
    Posts:
    3
  5. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    I always make my own custom Inspector scripts. That provides you with wayyyyy more flexibility. I got started in that by studying how Pool Manager did theirs. Check em out sometime!
     
  6. GaskellGames

    GaskellGames

    Joined:
    Apr 30, 2021
    Posts:
    2
    For anyone looking at this after all this time, here's part of my custom inspector V's the rigidbody inspector:

    upload_2023-10-3_21-50-40.png

    Just add the following into OnInspectorGUI() for a custom editor script, assuming you have public variables or getters/setters for the 6 bools: positionX, positionY, positionZ, rotationX, rotationY, rotationZ

    Code (CSharp):
    1.  
    2.  
    3. ClassName className = (ClassName)target;
    4. serializedObject.Update();
    5.  
    6. FoldoutGroup = EditorGUILayout.Foldout(FoldoutGroup, "Constraints");
    7.             if (FoldoutGroup)
    8.             {
    9.                 EditorGUILayout.BeginHorizontal();
    10.                 EditorGUI.indentLevel++;
    11.                 EditorGUILayout.PrefixLabel("Freeze Position");
    12.                 EditorGUI.indentLevel--;
    13.                 className.positionX = EditorGUILayout.ToggleLeft("X", className.positionX, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    14.                 className.positionY = EditorGUILayout.ToggleLeft("Y", className.positionY, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    15.                 className.positionZ = EditorGUILayout.ToggleLeft("Z", className.positionZ, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    16.                 EditorGUILayout.EndHorizontal();
    17.                
    18.                 EditorGUILayout.BeginHorizontal();
    19.                 EditorGUI.indentLevel++;
    20.                 EditorGUILayout.PrefixLabel("Freeze Rotation");
    21.                 EditorGUI.indentLevel--;
    22.                 className.rotationX = EditorGUILayout.ToggleLeft("X", className.rotationX, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    23.                 className.rotationY = EditorGUILayout.ToggleLeft("Y", className.rotationY, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    24.                 className.rotationZ = EditorGUILayout.ToggleLeft("Z", className.rotationZ, GUILayout.Width(28), GUILayout.ExpandWidth(false));
    25.                 EditorGUILayout.EndHorizontal();
    26.             }
    27.  
    28.  
     
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,622
    10 year necropost.
     
Thread Status:
Not open for further replies.