Created
July 4, 2015 11:06
-
-
Save takashicompany/b67e4d5e480c0b494cd5 to your computer and use it in GitHub Desktop.
Unity Transform's path extension.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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