Advertisement
ilih

Untitled

Dec 8th, 2017
88
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /// <summary>
  2.         /// Display Scene hierarchy in TreeView.
  3.         /// </summary>
  4.         public void SceneHierarchy2Tree()
  5.         {
  6.             var objects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
  7.  
  8.             HierarchyNodes.BeginUpdate();
  9.             HierarchyNodes.Clear();
  10.             foreach (var go in objects)
  11.             {
  12.                 HierarchyNodes.Add(Transform2Node(go.transform));
  13.             }
  14.             HierarchyNodes.EndUpdate();
  15.  
  16.             Tree.Nodes = HierarchyNodes;
  17.         }
  18.  
  19.         /// <summary>
  20.         /// Create node from transform.
  21.         /// </summary>
  22.         /// <param name="transform">Transform.</param>
  23.         /// <returns>Node.</returns>
  24.         protected TreeNode<TreeViewItem> Transform2Node(Transform transform)
  25.         {
  26.             var item = new TreeViewItem(transform.name);
  27.  
  28.             var nodes = new ObservableList<TreeNode<TreeViewItem>>();
  29.             foreach (Transform child in transform)
  30.             {
  31.                 nodes.Add(Transform2Node(child));
  32.             }
  33.  
  34.             var node = new TreeNode<TreeViewItem>(item, nodes, nodeIsExpanded: true, nodeIsVisible: transform.gameObject.activeSelf);
  35.  
  36.             return node;
  37.         }
Advertisement
RAW Paste Data Copied
Advertisement