using UnityEngine;
using System.Text;
// *** 静态类
public static class Extensions
{
/// <summary>
/// // *** 获取某对象从根节点到自身的路径
/// </summary>
public static string GetPath(this Transform _tra)
{
if (_tra == null)
{
UnityEngine.Debug.Log("对象为空"+_tra.name);
}
StringBuilder tempPath = new StringBuilder(_tra.name);
Transform tempTra = _tra;
string g = "/";
while (tempTra.parent != null)
{
tempTra = tempTra.parent;
tempPath.Insert(0, tempTra.name + g);
}
//Debug.Log("路径: " + tempPath);
return tempPath.ToString();
}
}
public class GameMAnagera :MonoBehaviour
{
private void Awake()
{
// *** 输出本脚本挂载的节点的路径
Debug.Log(transform.GetPath());
}
}