void Awake()
 {
     if (m_TreeElements.Count == 0)
     {
         DialogTreeElement dialogTreeElement = new DialogTreeElement("Root", -1, 0);
         m_TreeElements.Add(dialogTreeElement);
     }
 }
Exemplo n.º 2
0
        void BottomToolBar(Rect rect)
        {
            GUILayout.BeginArea(rect);

            using (new EditorGUILayout.HorizontalScope())
            {
                var style = "miniButton";
                if (GUILayout.Button("Expand All", style))
                {
                    treeView.ExpandAll();
                }

                if (GUILayout.Button("Collapse All", style))
                {
                    treeView.CollapseAll();
                }

                GUILayout.FlexibleSpace();

                GUILayout.Label(m_TreeAsset != null ? AssetDatabase.GetAssetPath(m_TreeAsset) : string.Empty);

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Add Item", style))
                {
                    Undo.RecordObject(m_TreeAsset, "Add Item To Asset");

                    // Add item as child of selection
                    var               selection = m_TreeView.GetSelection();
                    TreeElement       parent    = (selection.Count == 1 ? m_TreeView.treeModel.Find(selection[0]) : null) ?? m_TreeView.treeModel.root;
                    int               depth     = parent != null ? parent.depth + 1 : 0;
                    int               id        = m_TreeView.treeModel.GenerateUniqueID();
                    DialogTreeElement element   = new DialogTreeElement(string.Format("Item{0}", id), depth, id);
                    m_TreeView.treeModel.AddElement(element, parent, 0);
                    DialogNodeGraph dialogNodeGraph = CreateInstance <DialogNodeGraph>();
                    AssetDatabase.CreateAsset(dialogNodeGraph, string.Format("Assets/{0}.asset", id));
                    AssetDatabase.Refresh();
                    element.DialogNodeGraph = dialogNodeGraph;
                    // Select newly created element
                    m_TreeView.SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame);
                }

                if (GUILayout.Button("Remove Item", style))
                {
                    Undo.RecordObject(m_TreeAsset, "Remove Item From Asset");
                    IList <int> elementIDs             = m_TreeView.GetSelection();
                    IList <DialogTreeElement> elements = m_TreeView.treeModel.GetData().Where(element => elementIDs.Contains(element.id)).ToArray();
                    foreach (DialogTreeElement item in elements)
                    {
                        DeleAsset(item);
                    }
                    m_TreeView.treeModel.RemoveElements(elementIDs);
                    AssetDatabase.Refresh();
                }
            }
            GUILayout.EndArea();
        }
Exemplo n.º 3
0
        private void DeleAsset(DialogTreeElement element)
        {
            if (element.hasChildren)
            {
                foreach (DialogTreeElement item in element.children)
                {
                    DeleAsset(item);
                }
            }
            string path = AssetDatabase.GetAssetPath(element.DialogNodeGraph);

            AssetDatabase.DeleteAsset(path);
        }
    void ToolBar()
    {
        using (new EditorGUILayout.HorizontalScope())
        {
            var style = "miniButton";
            if (GUILayout.Button("Expand All", style))
            {
                m_TreeView.ExpandAll();
            }

            if (GUILayout.Button("Collapse All", style))
            {
                m_TreeView.CollapseAll();
            }

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Add Item", style))
            {
                Undo.RecordObject(asset, "Add Item To Asset");

                // Add item as child of selection
                var         selection = m_TreeView.GetSelection();
                TreeElement parent    = (selection.Count == 1 ? m_TreeView.treeModel.Find(selection[0]) : null) ?? m_TreeView.treeModel.root;
                int         depth     = parent != null ? parent.depth + 1 : 0;
                int         id        = m_TreeView.treeModel.GenerateUniqueID();
                var         element   = new DialogTreeElement("Item " + id, depth, id);
                m_TreeView.treeModel.AddElement(element, parent, 0);

                // Select newly created element
                m_TreeView.SetSelection(new[] { id }, TreeViewSelectionOptions.RevealAndFrame);
            }

            if (GUILayout.Button("Remove Item", style))
            {
                Undo.RecordObject(asset, "Remove Item From Asset");
                var selection = m_TreeView.GetSelection();
                m_TreeView.treeModel.RemoveElements(selection);
            }

            if (GUILayout.Button("Save"))
            {
                EditorUtility.SetDirty(asset);//这里就是关键的一句.其中SkillInfoData是脚本化对象.//2020-4-12, 这句可以直接写在原类中的SaveFile()函数中.
            }
        }
    }