public FolderNode Add(string value)
 {
     FolderNode child = new FolderNode {value = value, parent = this};
     children.Add(child);
     return child;
 }
        private static void AddFile(string[] paths, int cursor, FolderNode node)
        {
            while (true)
            {
                // done
                if (cursor == paths.Length)
                {
                    return;
                }

                FolderNode nextNode = node.GetNode(paths[cursor]);

                // not found
                if (nextNode == null)
                {
                    FolderNode newNode = node.Add(paths[cursor]);
                    cursor = cursor + 1;
                    node = newNode;
                }
                else
                {
                    cursor = cursor + 1;
                    node = nextNode;
                }
            }
        }
        private static void ReloadAll()
        {
            SaveData.FileSavedEvent -= OnFileSaved;
            SaveData.FileSavedEvent += OnFileSaved;

            files = SaveData.GetAllFiles();
            rootNode = new FolderNode {value = "root"};

            foreach (string file in files)
            {
                string[] paths = file.Split(SaveData.Slash[0]);
                AddFile(paths, 0, rootNode);
            }
        }
        private static void DrawNode(FolderNode node)
        {
            // no children
            if (node.children.Count == 0)
            {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space((EditorGUI.indentLevel - 1) * Indent);
                    Color cachedColor = GUI.color;
                    GUI.color = currentFile == node.value && currentPath == node.Path() ? Color.gray : cachedColor;
                    if (GUILayout.Button(node.value))
                    {
                        currentPath = node.Path();
                        currentFile = node.value;
                        currentParent = node.parent;
                        currentData = SaveData.LoadFromPath<object>(currentPath + currentFile);
                    }
                    GUI.color = cachedColor;
                }
                GUILayout.EndHorizontal();
                return;
            }

            if (node != rootNode)
            {
                EditorGUILayout.LabelField(node.value, currentParent == node ? EditorStyles.boldLabel : EditorStyles.label);
                EditorGUI.indentLevel++;
            }
            foreach (FolderNode child in node.children)
            {
                DrawNode(child);
            }
            EditorGUI.indentLevel--;
        }