I’m not sure how to ask this question or subsequently search for it. So, here is a picture.
![1242336--53108--$class-Rigidbody-0.jpg](https://europe1.discourse-cdn.com/unity/original/3X/3/3/33538448dffb43b2cd99aae2e387b12de8d62702.jpeg)
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
![1242336--53107--$6t71YR1.jpg](https://europe1.discourse-cdn.com/unity/original/4X/a/0/7/a07074c04c50ec2445d98d7ed00befe450b6bb43.jpeg)
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.
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
2 Likes
Ah. Unity - Scripting API: PropertyDrawer was what I was looking for.
Thank you,
David
2 Likes
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!
For anyone looking at this after all this time, here’s part of my custom inspector V’s the rigidbody inspector:
![9386876--1313108--upload_2023-10-3_21-50-40.png](https://europe1.discourse-cdn.com/unity/original/3X/f/9/f97b839c655072b6f8ee8d2f22f30d827204be56.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
ClassName className = (ClassName)target;
serializedObject.Update();
FoldoutGroup = EditorGUILayout.Foldout(FoldoutGroup, "Constraints");
if (FoldoutGroup)
{
EditorGUILayout.BeginHorizontal();
EditorGUI.indentLevel++;
EditorGUILayout.PrefixLabel("Freeze Position");
EditorGUI.indentLevel--;
className.positionX = EditorGUILayout.ToggleLeft("X", className.positionX, GUILayout.Width(28), GUILayout.ExpandWidth(false));
className.positionY = EditorGUILayout.ToggleLeft("Y", className.positionY, GUILayout.Width(28), GUILayout.ExpandWidth(false));
className.positionZ = EditorGUILayout.ToggleLeft("Z", className.positionZ, GUILayout.Width(28), GUILayout.ExpandWidth(false));
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
EditorGUI.indentLevel++;
EditorGUILayout.PrefixLabel("Freeze Rotation");
EditorGUI.indentLevel--;
className.rotationX = EditorGUILayout.ToggleLeft("X", className.rotationX, GUILayout.Width(28), GUILayout.ExpandWidth(false));
className.rotationY = EditorGUILayout.ToggleLeft("Y", className.rotationY, GUILayout.Width(28), GUILayout.ExpandWidth(false));
className.rotationZ = EditorGUILayout.ToggleLeft("Z", className.rotationZ, GUILayout.Width(28), GUILayout.ExpandWidth(false));
EditorGUILayout.EndHorizontal();
}
3 Likes