0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Unity】1つ下の子だけを選択するEditor拡張

Posted at

背景

オブジェクトを円状に並べる際、子を回転させて配置する方法がありますが、子を取り出すのが面倒なので1つ下の子だけを選択する拡張Editorを作りました。

image.png

Editor拡張を入れたら対象のオブジェクトを複数選択し、右クリックすると出るメニューからSelect children one level belowを選択すると、1つ下の子が選ばれます。

image.png

備考

オブジェクトの配置方法に関しては他にも専用の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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?