背景
オブジェクトを円状に並べる際、子を回転させて配置する方法がありますが、子を取り出すのが面倒なので1つ下の子だけを選択する拡張Editorを作りました。
Editor拡張を入れたら対象のオブジェクトを複数選択し、右クリックすると出るメニューからSelect children one level below
を選択すると、1つ下の子が選ばれます。
備考
オブジェクトの配置方法に関しては他にも専用のEditor拡張を導入したり、Transformに数式を入力したりする方法もあるようです。
コード
ChildrenSelectorEditor.cs
#if UNITY_EDITOR
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
public class ChildrenSelectorEditor
{
private static bool isSelected = false;
[MenuItem("GameObject/Select children one level below", false, 1000)]
public static void SelectChildren()
{
if (isSelected) return;
isSelected = true;
EditorApplication.delayCall += () => isSelected = false;
var children = new List<GameObject>();
foreach (var go in Selection.gameObjects.ToArray())
{
var transform = go.transform;
for (int i = 0; i < transform.childCount; i++) children.Add(transform.GetChild(i).gameObject);
}
Selection.objects = children.ToArray();
}
}
#endif