使い方
Hierarchy の オブジェクトを右クリックすると 「CopyPath」が出てくるので
それを選択するとルートからのパスを取得できる
例えば下図のオブジェクトのパスをコピーすると Main Camera/Root/Path/Item
になる
コード
using System.Text; using UnityEditor; using UnityEngine; public static class CopyHierarchyPath { [MenuItem("GameObject/CopyPath", false, int.MinValue)] private static void CopyPath() { var active = Selection.activeGameObject; if (active == null) return; var obj = active as GameObject; var builder = new StringBuilder(obj.transform.name); var current = obj.transform.parent; while (current != null) { builder.Insert(0, current.name + "/"); current = current.parent; } GUIUtility.systemCopyBuffer = builder.ToString(); } }