Ejemplo n.º 1
0
 /// <summary>
 /// 删除故事树
 /// </summary>
 private void DeleteStoryTree(StoryTree tree)
 {
     if (tree == null)
     {
         ShowNotification(new GUIContent("未指定要删除的故事树"));
     }
     else
     {
         string str = "确认要删除故事树 " + tree.name + " 以及其所有节点吗?这将无法恢复。";
         if (EditorUtility.DisplayDialog("警告", str, "确认", "取消"))
         {
             if (tree.Nodes != null)
             {
                 for (int i = 0; i < tree.Nodes.Count; i++)
                 {
                     if (tree.Nodes[i] != null)
                     {
                         DeleteStoryNode(tree.Nodes[i], false);
                         i--;
                     }
                 }
                 Debug.Log("已删除所有故事树节点资源");
             }
             Debug.Log("已删除故事树资源:" + tree.name + ".asset");
             m_StoryTrees.Remove(tree);
             File.Delete(Application.dataPath + ConfigInfo.StoryTreeFolder + "/" + tree.name + ".asset");
             AssetDatabase.Refresh();
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 清除故事树节点列表的空节点
 /// </summary>
 private void ClearStoryTreeNullNodes(StoryTree tree)
 {
     if (tree.Nodes != null)
     {
         //移除空位
         for (int i = 0; i < tree.Nodes.Count; i++)
         {
             if (tree.Nodes[i] == null)
             {
                 tree.Nodes.RemoveAt(i);
                 i--;
             }
         }
     }
     if (tree.EndNodes != null)
     {
         //移除空位
         for (int i = 0; i < tree.EndNodes.Count; i++)
         {
             if (tree.EndNodes[i] == null)
             {
                 tree.EndNodes.RemoveAt(i);
                 i--;
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建故事树
        /// </summary>
        private void CreateStoryTree()
        {
            StoryTree storyTree = AssetCreator <StoryTree> .CreateAsset(ConfigInfo.StoryTreeFolder, "Story");

            if (storyTree != null)
            {
                OpenStoryTree(storyTree);
                AssetDatabase.Refresh();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 打开故事树
 /// </summary>
 /// <param name="tree"></param>
 private void OpenStoryTree(StoryTree tree)
 {
     if (tree != null)
     {
         m_CurrentStoryTree = tree;
         ClearStoryTreeNullNodes(m_CurrentStoryTree);
         Selection.activeObject = m_CurrentStoryTree;
         ShowNotification(new GUIContent("故事树打开成功:" + m_CurrentStoryTree.name));
     }
     else
     {
         Debug.LogError("故事树打开失败:对象为空");
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建故事节点
        /// </summary>
        private void CreateStoryNode(StoryTree tree)
        {
            StoryNode storyNode = AssetCreator <StoryNode> .CreateAsset(ConfigInfo.StoryNodeFolder, tree.name);

            if (storyNode != null)
            {
                storyNode.Rect = new Rect(m_MousePos.x, m_MousePos.y, ConfigInfo.DefaultNodeSize.x, ConfigInfo.DefaultNodeSize.y);
                if (tree.Nodes == null)
                {
                    tree.Nodes = new List <StoryNode>();
                }
                tree.Nodes.Add(storyNode);
                Selection.activeObject = storyNode;
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 绘制故事树
 /// </summary>
 /// <param name="storyTree"></param>
 private void DrawStoryTree(StoryTree tree)
 {
     if (tree != null)
     {
         if (tree.Nodes != null)
         {
             for (int i = 0; i < tree.Nodes.Count; i++)
             {
                 int j = tree.Nodes.Count - 1 - i;
                 if (tree.Nodes[j] != null)
                 {
                     DrawStoryNode(tree.Nodes[j]);
                 }
             }
         }
     }
     else
     {
         ShowNotification(new GUIContent("创建或打开一个故事树"));
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 关闭故事树
 /// </summary>
 private void CloseStoryTree()
 {
     m_CurrentStoryTree = null;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 刷新窗口
        /// </summary>
        private void Refresh()
        {
            wantsMouseMove = true;
            ClearTempConnect();
            if (!Directory.Exists(ConfigInfo.StoryTreeFolder))
            {
                Directory.CreateDirectory(ConfigInfo.StoryTreeFolder);
                Debug.LogWarning("文件夹不存在,已重新创建:" + ConfigInfo.StoryTreeFolder);
            }

            //遍历故事树文件夹,获取所有该文件夹内的故事树文件
            List <StoryTree> tempStoryTrees = new List <StoryTree>();
            DirectoryInfo    TheFolder      = new DirectoryInfo(ConfigInfo.StoryTreeFolder);

            foreach (FileInfo NextFile in TheFolder.GetFiles())
            {
                string[] name = NextFile.Name.Split('.');
                if (name[1] == "asset" & name.Length == 2)
                {
                    //StoryTree storyTree = Resources.Load<StoryTree>("StoryTrees/" + name[0]);
                    StoryTree storyTree = AssetCreator <StoryTree> .GetAsset(ConfigInfo.StoryTreeFolder + "/" + name[0] + ".asset");

                    if (storyTree != null)
                    {
                        tempStoryTrees.Add(storyTree);
                    }
                }
            }

            if (m_StoryTrees == null)
            {
                m_StoryTrees = new List <StoryTree>();
            }

            //检测窗体引用的故事树是否还存在
            for (int i = 0; i < m_StoryTrees.Count; i++)
            {
                bool isHave = false;
                foreach (StoryTree tempStoryTree in tempStoryTrees)
                {
                    if (m_StoryTrees[i].Equals(tempStoryTree))
                    {
                        isHave = true;
                        break;
                    }
                }
                if (!isHave)
                {
                    m_StoryTrees.Remove(m_StoryTrees[i]);
                }
            }
            //检测文件夹内是否有新的故事树
            foreach (StoryTree tempStoryTree in tempStoryTrees)
            {
                bool isSame = false;
                if (m_StoryTrees.Count > 0)
                {
                    for (int i = 0; i < m_StoryTrees.Count; i++)
                    {
                        if (tempStoryTree.Equals(m_StoryTrees[i]))
                        {
                            isSame = true;
                            break;
                        }
                    }
                }
                if (!isSame)
                {
                    m_StoryTrees.Add(tempStoryTree);
                }
            }

            if (m_StoryTrees.Count == 0)
            {
                m_CurrentStoryTree = null;
            }
        }