[MenuItem("GameObject/copy节点相对prefab的路径", false, 36)] public static void CopyPathByPrefab() { UnityEngine.Object obj = Selection.activeObject; if (obj == null) { Debug.LogError("You must select Obj first!"); return; } string result = AssetDatabase.GetAssetPath(obj); if (string.IsNullOrEmpty(result))//如果不是资源则在场景中查找 { Transform selectChild = Selection.activeTransform; if (selectChild != null) { result = selectChild.name; while (selectChild.parent != null) { selectChild = selectChild.parent; if(selectChild.parent !=null) { result = string.Format("{0}/{1}", selectChild.name, result); } } } } ClipBoard.Copy(result); Debug.Log(string.Format("The gameobject:{0}'s path has been copied to the clipboard!", obj.name)); }