The problem is in the loop when i set the includeChildren bool to false again i can't then select individual toggles from the include1 array because includeChildren set the include1[i] to false all the time.
if(includeChildren)
{
include1[i] = true;
}
else
{
include1[i] = false;
}
include1[i] = EditorGUILayout.Toggle("Include Children", include1[i], GUILayout.ExpandWidth(true));
The full script :
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class RenameSelected : EditorWindow
{
private static readonly Vector2Int size = new Vector2Int(500, 500);
private string childrenPrefix;
private int startIndex;
private bool showPosition = false;
private bool includeChildren = false;
private bool[] include1;
private bool a = false;
private GameObject[] objects;
private Vector2 scrollPos;
[MenuItem("GameObject/Rename Selected")]
public static void Init()
{
EditorWindow window = GetWindow<RenameSelected>();
window.minSize = size;
window.maxSize = size;
}
private void OnSelectionChange()
{
objects = Selection.gameObjects;
}
private void OnEnable()
{
objects = Selection.gameObjects;
include1 = new bool[objects.Length];
}
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;
EditorGUILayout.BeginHorizontal();
{
GUILayoutOption[] options = { GUILayout.MaxWidth(300.0f), GUILayout.MinWidth(300.0f) };
objects[i] = (GameObject)EditorGUILayout.ObjectField(i.ToString(), objects[i], typeof(GameObject), true, options);
EditorGUIUtility.labelWidth = 112;
if(includeChildren)
{
include1[i] = true;
}
else
{
include1[i] = false;
}
include1[i] = EditorGUILayout.Toggle("Include Children", include1[i], GUILayout.ExpandWidth(true));
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndScrollView();
EditorGUI.indentLevel--;
}
GUILayout.FlexibleSpace();
if (GUILayout.Button("Rename Objects"))
{
}
Repaint();
}
}
I tried this too but the same result i can't check the toggle boxes individual at all :
if (includeChildren)
{
include1[i] = true;
}
else
{
if(include1[i] != false)
{
include1[i] = false;
}
}