copy節點相對prefab的路徑 (unity小工具)
阿新 • • 發佈:2021-07-12
[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)); }