When i scroll up/down the Objects also scrolling and i want only the items in the array to be scrolling not the title Objects.
Second problem is how to make the scrolling to be wider ? i tried to change the width from 100 to 500 but it changed the position pushed to the right by 500 didn't make it wider.
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(100), GUILayout.Height(100));
The 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(250, 100);
private string childrenPrefix;
private int startIndex;
private static SerializedObject _serializedObject;
public GameObject[] objects;
Vector2 scrollPos;
[MenuItem("GameObject/Rename Selected")]
public static void ShowWindow()
{
EditorWindow window = GetWindow<RenameSelected>();
window.minSize = size;
window.maxSize = size;
}
private void OnSelectionChange()
{
objects = Selection.gameObjects;
}
private void OnEnable()
{
ScriptableObject target = this;
_serializedObject = new SerializedObject(target);
objects = Selection.gameObjects;
}
private void OnGUI()
{
childrenPrefix = EditorGUILayout.TextField("Children prefix", childrenPrefix);
startIndex = EditorGUILayout.IntField("Start index", startIndex);
_serializedObject.Update();
EditorGUILayout.BeginHorizontal();
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(100), GUILayout.Height(100));
SerializedProperty serializedProperty = _serializedObject.FindProperty("objects");
EditorGUILayout.PropertyField(serializedProperty, true);
EditorGUILayout.EndScrollView();
EditorGUILayout.EndHorizontal();
Repaint();
if (GUILayout.Button("Rename children"))
{
for (int objectI = 0; objectI < objects.Length; objectI++)
{
Transform selectedObjectT = objects[objectI].transform;
for (int childI = 0, i = startIndex; childI < selectedObjectT.childCount; childI++) selectedObjectT.GetChild(childI).name = $"{childrenPrefix}{i++}";
}
}
}
}
I tried this and the result is almost as i wanted but now the parent Objects is gone. i want to see the parent of the array items and to be able to expand the array items but when scrolling that only the items in the array to be scrolled not the parent !
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 static SerializedObject _serializedObject;
public GameObject[] objects;
Vector2 scrollPos;
SerializedProperty serializedProperty;
[MenuItem("GameObject/Rename Selected")]
public static void ShowWindow()
{
EditorWindow window = GetWindow<RenameSelected>();
window.minSize = size;
window.maxSize = size;
}
private void OnSelectionChange()
{
objects = Selection.gameObjects;
}
private void OnEnable()
{
ScriptableObject target = this;
_serializedObject = new SerializedObject(target);
serializedProperty = _serializedObject.FindProperty("objects");
objects = Selection.gameObjects;
}
private void OnGUI()
{
childrenPrefix = EditorGUILayout.TextField("Children prefix", childrenPrefix);
startIndex = EditorGUILayout.IntField("Start index", startIndex);
_serializedObject.Update();
scrollPos =
EditorGUILayout.BeginScrollView(scrollPos);
for(int i = 0; i < serializedProperty.arraySize; i++)
{
var obj = serializedProperty.GetArrayElementAtIndex(i);
EditorGUILayout.PropertyField(obj, new GUIContent("Object " + i), true);
}
EditorGUILayout.EndScrollView();
Repaint();
GUILayout.Space(5);
if (GUILayout.Button("Rename children"))
{
for (int objectI = 0; objectI < objects.Length; objectI++)
{
Transform selectedObjectT = objects[objectI].transform;
for (int childI = 0, i = startIndex; childI < selectedObjectT.childCount; childI++) selectedObjectT.GetChild(childI).name = $"{childrenPrefix}{i++}";
}
}
}
}

