LoginSignup
2
0

More than 5 years have passed since last update.

【Unityショートカットキー自作】ヒエラルキーで選択しているオブジェクトと同じ階層にあるオブジェクトだけを全選択するショートカットキーを自作する

Last updated at Posted at 2015-10-23

同じ階層のオブジェクトだけを全選択させるショートカットキーがほしかったので作ってみました。

image

ソースコード

Ctrl + Alt + Aを押すと同じ階層にあるオブジェクトだけが選択されます(Windows)

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;

public class CustomShortCutKey : Editor
{
    [MenuItem("Shortcut/SelectChildAll Ctrl + Alt + A %&a")]
    static public void SelectAll()
    {
        Debug.Log("SelectChildAll");

        if (Selection.activeTransform != null)//Hierrchyのオブジェクトを選択している
        {
            Transform parent = Selection.activeTransform.parent;

            List<Object> objects = new List<Object>();

            for (int i = 0; i < parent.childCount; i++)
            {
                objects.Add(parent.GetChild(i).gameObject);
            }

            Selection.objects = objects.ToArray();
        }
    }
}

参考

Qiita - Unityでショートカットキーの自作
http://qiita.com/okuhiiro/items/f6d0f0fe99d04fe03e83

2
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
2
0