美文网首页
Unity 拷贝Hierarchy中的物体路径

Unity 拷贝Hierarchy中的物体路径

作者: 114105lijia | 来源:发表于2022-09-23 14:33 被阅读0次
    #if UNITY_EDITOR
    
    using UnityEditor;
    using UnityEngine;
    
    
    namespace UnicomFramework.Editor
    {
        public class GameObjectCopyPath : UnityEditor.Editor
        {
            private static TextEditor textEditor = new TextEditor();
            [MenuItem("GameObject/CopyPath _F12", priority = 12)]
            private static void CopyPathOption()
            {
                if (Selection.activeGameObject)
                {
                    string s = GetTransPath(Selection.activeGameObject.transform);
                    textEditor.text = s;
                    textEditor.OnFocus();
                    textEditor.Copy();
                    Debug.Log("[CopyPath]:" + s);
    
                }
            }
    
            /// <summary>
            /// 获得GameObject在Hierarchy中的完整路径
            /// </summary>
            public static string GetTransPath(Transform trans)
            {
                if (!trans.parent)
                {
                    return trans.name;
    
                }
                return GetTransPath(trans.parent) + "/" + trans.name;
            }
    
        } 
    }
    
    #endif
    

    相关文章

      网友评论

          本文标题:Unity 拷贝Hierarchy中的物体路径

          本文链接:https://www.haomeiwen.com/subject/gtjnortx.html