Created
January 22, 2021 21:32
-
-
Save Oppodelldog/2e881fc12cf0130fbab361945b32baab to your computer and use it in GitHub Desktop.
create game objects tree id - may be used as scene persisting unique id (as long as long tree is not changed of course)
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
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace GameObjectHelper | |
{ | |
public static class TreeId | |
{ | |
public static string Get(Transform endOfTree) | |
{ | |
var treeId = new List<string>(); | |
var t = endOfTree; | |
while (t != null) | |
{ | |
treeId.Add(t.GetSiblingIndex().ToString()); | |
t = t.parent; | |
} | |
treeId.Reverse(); | |
return String.Join("-", treeId); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment