Skip to content

Instantly share code, notes, and snippets.

@Oppodelldog
Created January 22, 2021 21:32
Show Gist options
  • Save Oppodelldog/2e881fc12cf0130fbab361945b32baab to your computer and use it in GitHub Desktop.
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)
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