Exemplo n.º 1
0
 public FolderNode Add(string value)
 {
     FolderNode child = new FolderNode {value = value, parent = this};
     children.Add(child);
     return child;
 }
Exemplo n.º 2
0
        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;
                }
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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--;
        }