copy节点相对prefab的路径 (unity小工具)

时间:2021-07-12
本文章向大家介绍copy节点相对prefab的路径 (unity小工具),主要包括copy节点相对prefab的路径 (unity小工具)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
    [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));

    }
改变自己

原文地址:https://www.cnblogs.com/sun-shadow/p/15001806.html