Skip to content

Instantly share code, notes, and snippets.

@takashicompany
Created July 4, 2015 11:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takashicompany/b67e4d5e480c0b494cd5 to your computer and use it in GitHub Desktop.
Save takashicompany/b67e4d5e480c0b494cd5 to your computer and use it in GitHub Desktop.
Unity Transform's path extension.
namespace TakashiCompany.Unity.Extension
{
using UnityEngine;
/// <summary>
/// Transform's path extension.
/// </summary>
public static class TransformPathExtension
{
/// <summary>
/// Gets the path from root.
/// </summary>
/// <returns>The path.</returns>
/// <param name="self">Self.</param>
public static string GetPath(this Transform self)
{
string path = self.gameObject.name;
Transform parent = self.parent;
while (parent != null)
{
path = parent.name + "/" + path;
parent = parent.parent;
}
return path;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment