以下の内容はhttps://baba-s.hatenablog.com/entry/2019/04/01/091000より取得しました。


【Unity】ゲームオブジェクトの Hierarchy におけるパスを取得できる拡張メソッド

ソースコード

using UnityEngine;

public static class GameObjectExt
{
    public static string GetHierarchyPath( this GameObject gameObject )
    {
        var path = gameObject.name;
        var parent = gameObject.transform.parent;

        while ( parent != null )
        {
            path = parent.name + "/" + path;
            parent = parent.parent;
        }

        return path;
    }
}

使用例

using UnityEngine;

public class Test : MonoBehaviour
{
    private void Awake()
    {
        Debug.Log( gameObject.GetHierarchyPath() );
    }
}

関連記事




以上の内容はhttps://baba-s.hatenablog.com/entry/2019/04/01/091000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14