I'm trying to add toggle checkboxes near each objectfield on the objectfield side beside it on the right side and not above it.
public void OnGUI()
{
GUILayout.Space(10);
childrenPrefix = EditorGUILayout.TextField("Rename prefix", childrenPrefix);
startIndex = EditorGUILayout.IntField("Start index", startIndex);
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren);
if (objects.Length == 0)
{
showPosition = false;
}
GUILayout.Space(20);
EditorGUI.BeginChangeCheck();
EditorGUILayout.GetControlRect(true, 16f, EditorStyles.foldout);
Rect foldRect = GUILayoutUtility.GetLastRect();
if (Event.current.type == EventType.MouseUp && foldRect.Contains(Event.current.mousePosition))
{
showPosition = !showPosition;
GUI.changed = true;
Event.current.Use();
}
showPosition = EditorGUI.Foldout(foldRect, showPosition, "Objects");
GUILayout.Space(2);
if (showPosition)
{
EditorGUI.indentLevel ;
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos);
for (int i = 0; i < objects.Length; i )
{
EditorGUIUtility.labelWidth = 50;
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren);
GUILayoutOption[] options = { GUILayout.MaxWidth(100.0f), GUILayout.MinWidth(300.0f) };
objects[i] = (GameObject)EditorGUILayout.ObjectField(i.ToString(), objects[i], typeof(GameObject), true,options);
}
EditorGUILayout.EndScrollView();
EditorGUI.indentLevel--;
}
When i'm adding this toggle line before ObjectField it's adding the toggle above it and i want the toggle to be near it on the right side of the objectfield field.
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren);
I tried this :
EditorGUILayout.BeginHorizontal();
{
GUILayoutOption[] options = { GUILayout.MaxWidth(100.0f), GUILayout.MinWidth(300.0f) };
objects[i] = (GameObject)EditorGUILayout.ObjectField(i.ToString(), objects[i], typeof(GameObject), true, options);
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren);
}
EditorGUILayout.EndHorizontal();
but you don't see the whole toggle string name Include Children but only Includ like this :
I tried to add the options to the toggle but it didn't change much :
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren, options);
I tried to switch the options max width to 700 and min width to 300 and the result is : horizontal scrollbar :
CodePudding user response:
You need to place it in a horizontal area.
EditorGUILayout.BeginHorizontal();
{
includeChildren = EditorGUILayout.Toggle("Include Children", includeChildren);
GUILayoutOption[] options = { GUILayout.MaxWidth(100.0f), GUILayout.MinWidth(300.0f) };
objects[i] = (GameObject)EditorGUILayout.ObjectField(i.ToString(), objects[i], typeof(GameObject), true,options);
}
EditorGUILayout.EndHorizontal();
Placing the toggle control line before your object field will result in the toggle being on the left.
Placing the toggle control after the object field will result in the toggle on the right.
CodePudding user response:
Solution to add EditorGUIUtility.labelWidth line before the toggle line :
EditorGUIUtility.labelWidth = 112;
include1 = EditorGUILayout.Toggle("Include Children", include1, GUILayout.ExpandWidth(true));
Result :