public void RepopulateTreeRecursively(GameObject target, TreeNode <HierarchyItem> parent)
        {
            HierarchyItem node = new HierarchyItem(target)
            {
                opened = false
            };

            bool createNew = true;
            TreeNode <HierarchyItem> child = new TreeNode <HierarchyItem>();

            foreach (TreeNode <HierarchyItem> item in parent.Children)
            {
                if (item.Item.source.Equals(target))
                {
                    createNew = false;
                    node      = item.Item;
                    child     = item;
                }
            }

            if (createNew)
            {
                child = parent.AddChild(node);
            }
            for (int i = 0; i < target.transform.childCount; i++)
            {
                PopulateTreeRecursively(target.transform.GetChild(i).gameObject, child);
            }
        }
 public void NavigateNodeRecursively(TreeNode <HierarchyItem> node, int depth = 0)
 {
     if (node.Item != null)
     {
         try
         {
             //UnityEngine.Debug.Log("Testing Item transform");
             //UnityEngine.Debug.Log(node.Item.source.name);
             if (node.Item.source.transform.childCount > 0)
             {
             }
             GUILayout.BeginHorizontal();
             GUILayout.Space(30 * depth);
             string arrow = "";
             if (node.Item.source.transform.childCount > 0)
             {
                 if (node.Item.opened)
                 {
                     arrow = down_arrow;
                 }
                 else
                 {
                     arrow = right_arrow;
                 }
                 if (GUILayout.Button(arrow, GUILayout.ExpandWidth(false)))
                 {
                     node.Item.opened = !node.Item.opened;
                     UnityEngine.Debug.Log(node.Item.opened);
                 }
             }
             else
             {
                 GUILayout.Space(30);
             }
             if (GUILayout.Button(node.Item.source.name))
             {
                 selectedGameObject = node.Item;
             }
             GUILayout.EndHorizontal();
         }
         catch (Exception e)
         {
         }
     }
     if (node.Item == null || node.Item.opened)
     {
         depth++;
         foreach (TreeNode <HierarchyItem> child in node.Children)
         {
             NavigateNodeRecursively(child, depth);
         }
     }
 }
        public void PopulateTreeRecursively(GameObject target, TreeNode <HierarchyItem> parent)
        {
            HierarchyItem node = new HierarchyItem(target)
            {
                opened = false
            };

            var child = parent.AddChild(node);

            for (int i = 0; i < target.transform.childCount; i++)
            {
                PopulateTreeRecursively(target.transform.GetChild(i).gameObject, child);
            }
        }