示例#1
0
        internal 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);
            }
        }
示例#2
0
        internal void LoadSceneObjects()
        {
            Scene scene = SceneManager.GetActiveScene();

            numGameObjects = scene.rootCount;

            HierarchyItem sceneItem = new HierarchyItem(null)
            {
                opened = false
            };

            sceneTree = new TreeNode <HierarchyItem>(sceneItem);
            foreach (GameObject go in scene.GetRootGameObjects())
            {
                PopulateTreeRecursively(go, sceneTree);
            }
        }
示例#3
0
        internal void NavigateNodeRecursively(TreeNode <HierarchyItem> node, int depth = 0)
        {
            try
            {
                if (node.Item.source != null)
                {
                    GUILayout.BeginHorizontal();
                    string text = "", skin = "TreeItem";

                    for (int i = 0; i < depth; i++)
                    {
                        text += "     ";
                    }

                    if (node.Item.source.transform.childCount > 0)
                    {
                        if (node.Item.opened)
                        {
                            text += down_arrow;
                        }
                        else
                        {
                            text += right_arrow;
                        }
                    }

                    text += node.Item.source.name;

                    if (selectedGameObject == node.Item)
                    {
                        skin = "TreeItemSelected";
                    }

                    if (GUILayout.Button(text, skin))
                    {
                        if (Input.GetMouseButtonUp(0))
                        {
                            //Left
                            node.Item.opened   = !node.Item.opened;
                            selectedGameObject = node.Item;
                        }
                        else if (Input.GetMouseButtonUp(1))
                        {
                            if (draggedGameObject != null)
                            {
                                draggedGameObject.source.transform.SetParent(node.Item.source.transform);
                                draggedGameObject = null;
                                //Replace the load with a more computationally efficient reload (todo)
                                LoadSceneObjects();
                            }
                            else if (draggedGameObject == null)
                            {
                                draggedGameObject = node.Item;
                            }
                        }
                    }

                    GUILayout.EndHorizontal();
                }
                else if (node.Item.source == null && depth == 0)
                {
                    GUILayout.BeginHorizontal();
                    string text = "", skin = "TreeItem";

                    for (int i = 0; i < depth; i++)
                    {
                        text += "     ";
                    }
                    if (node.Item.opened)
                    {
                        text += down_arrow;
                    }
                    else
                    {
                        text += right_arrow;
                    }

                    text += "Scene";

                    if (selectedGameObject == node.Item)
                    {
                        skin = "TreeItemSelected";
                    }

                    if (GUILayout.Button(text, skin))
                    {
                        if (Input.GetMouseButtonUp(0))
                        {
                            //Left
                            node.Item.opened = !node.Item.opened;
                        }
                        else if (Input.GetMouseButtonUp(1))
                        {
                            if (draggedGameObject != null)
                            {
                                draggedGameObject.source.transform.SetParent(null);
                                draggedGameObject = null;
                                //Replace the load with a more computationally efficient reload (todo)
                                LoadSceneObjects();
                            }
                        }
                    }

                    GUILayout.EndHorizontal();
                }
            }
            catch (Exception e)
            {
                Debug.Log(e.StackTrace);
                Debug.Log(e.Message);
            }
            if (node.Item.opened)
            {
                depth++;
                foreach (TreeNode <HierarchyItem> child in node.Children)
                {
                    NavigateNodeRecursively(child, depth);
                }
            }
        }