public void Layout()
        {
            //EditorGUILayout.Space();
            EditorGUILayout.Separator();
            string str = path.Substring(path.LastIndexOf("\\") + 1);

            isFoldout = EditorGUILayout.Foldout(isFoldout, str);
            if (isFoldout)
            {
                GUILayout.BeginVertical();
                for (int i = 0; i < dirs.Count; ++i)
                {
                    dirs[i].Layout();
                }
                for (int i = 0; i < files.Count; ++i)
                {
                    string fileName = files[i];
                    str = fileName.Substring(fileName.LastIndexOf("\\") + 1);
                    if (GUILayout.Button(str, GUILayout.Width(200), GUILayout.Height(25)))
                    {
                        OperCmdInfo cmdInfo = new OperCmdInfo();
                        cmdInfo.cmd   = OperCmd.OPEN_FILE;
                        cmdInfo.param = files[i];
                        NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
                    }
                }
                GUILayout.EndVertical();
            }
        }
        public void OnShow()
        {
            this.minSize = new Vector2(windowWidth, windowHeight);
            filesList.Reload(this.edtorName);
            OperCmdInfo cmdInfo = new OperCmdInfo();

            cmdInfo.cmd = OperCmd.CREATE_NEW;
            NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
        }
        void DeleteCmd(object obj)
        {
            int         id      = (int)obj;
            OperCmdInfo cmdInfo = new OperCmdInfo();

            cmdInfo.cmd   = OperCmd.REMOVE_NODE;
            cmdInfo.param = id;
            AddCmd(cmdInfo);
        }
        public virtual void DrawInNodeList()
        {
            Texture2D  texture = NodeFlowDrawHelper.CreateTagTex(color, color, 6, 6);
            GUIContent guic    = new GUIContent(this.desc, texture);

            if (GUILayout.Button(guic, GUILayout.Width(160), GUILayout.Height(30)))
            {
                OperCmdInfo cmdInfo = new OperCmdInfo();
                cmdInfo.cmd   = OperCmd.CREATE_NODE;
                cmdInfo.param = this;
                NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
            }
        }
        void CloneCmd(object obj)
        {
            int id = (int)obj;

            if (editorMode.mCurrent == null)
            {
                return;
            }
            Node node = editorMode.mCurrent.GetNodeByID(id);

            if (node == null)
            {
                return;
            }
            OperCmdInfo cmdInfo = new OperCmdInfo();

            cmdInfo.cmd   = OperCmd.CLONE_NODE;
            cmdInfo.param = node;
            AddCmd(cmdInfo);
        }
        void OnGUI()
        {
            //command button
            {
                Rect rect = new Rect(0, 0, position.width, commandHeight);
                GUILayout.BeginArea(rect);
                GUI.Box(new Rect(0, 0, rect.width, rect.height), "");
                GUILayout.BeginHorizontal();

                if (GUILayout.Button("文件列表", GUILayout.Width(95), GUILayout.Height(30)))
                {
                    isFileListMode = true;
                }
                if (GUILayout.Button("节点列表", GUILayout.Width(95), GUILayout.Height(30)))
                {
                    isFileListMode = false;
                }
                GUILayout.Label("  ", GUILayout.Width(30), GUILayout.Height(30));
                if (GUILayout.Button("创建空NodeFlow", GUILayout.Width(130), GUILayout.Height(30)))
                {
                    OperCmdInfo cmdInfo = new OperCmdInfo();
                    cmdInfo.cmd = OperCmd.CREATE_NEW;
                    NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
                }
                if (GUILayout.Button("保存NodeFlow", GUILayout.Width(130), GUILayout.Height(30)))
                {
                    OperCmdInfo cmdInfo = new OperCmdInfo();
                    cmdInfo.cmd = OperCmd.SAVE_FILE;
                    NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
                }
                if (editorMode.IsNewNodeFlow())
                {
                    GUI.FocusControl("-1");
                }
                if (editorMode.mCurrent != null)
                {
                    string flowName = "文件名:";
                    editorMode.mCurrent.name = EditorGUILayout.TextField(flowName, editorMode.mCurrent.name);

                    if (GUILayout.Button("打开所在文件夹", GUILayout.Width(150), GUILayout.Height(30)))
                    {
                        string path = editorMode.mCurrent.name;

                        if (path.Length == 0)
                        {
                            path = filesList.GetDirRoot(edtorName);
                        }
                        else
                        {
                            path = path.Replace("/", "\\");
                            int idx = path.LastIndexOf("\\");
                            path = path.Substring(0, idx);
                        }
                        System.Diagnostics.Process.Start("explorer", path);
                    }
                }
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }

            //file list view
            {
                Rect rect = new Rect(0, commandHeight, leftWidth, position.height - commandHeight);
                GUILayout.BeginArea(rect);
                GUI.Box(new Rect(0, 0, rect.width, rect.height), "");
                GUILayout.BeginVertical();
                fileListViewPos = EditorGUILayout.BeginScrollView(fileListViewPos, GUILayout.Width(rect.width), GUILayout.Height(rect.height));
                if (isFileListMode)
                {
                    filesList.Layout();
                }
                else
                {
                    NodeListLayoutHelper.Layout(nodeDef);
                }
                EditorGUILayout.EndScrollView();
                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            //property view
            {
                Rect rect = new Rect(position.width - rightWidth, commandHeight, rightWidth, position.height - commandHeight);
                GUILayout.BeginArea(rect);
                GUI.Box(new Rect(0, 0, rect.width, rect.height), "");
                GUILayout.BeginVertical();
                propertyViewPos = EditorGUILayout.BeginScrollView(propertyViewPos, GUILayout.Width(rect.width), GUILayout.Height(rect.height));
                editorMode.ShowProperty(selectedNodeId);
                EditorGUILayout.EndScrollView();
                GUILayout.EndVertical();
                GUILayout.EndArea();
            }

            //nodeflow view
            {
                float skillFlowWidth = position.width - leftWidth - rightWidth;
                Rect  rect           = new Rect(leftWidth, commandHeight, skillFlowWidth, position.height - commandHeight);
                GUILayout.BeginArea(rect);
                GUI.Box(new Rect(0, 0, rect.width, rect.height), "");
                GUILayout.BeginHorizontal();
                nodeFlowViewPos = EditorGUILayout.BeginScrollView(nodeFlowViewPos, GUILayout.Width(rect.width), GUILayout.Height(rect.height));
                GUILayout.Label("", GUILayout.Width(rect.width * 3), GUILayout.Height(rect.height * 3));
                BeginWindows();
                editorMode.Draw();
                //link
                if (curNextNode != null)
                {
                    Vector2 start = curNextNode.rect.center;
                    start.x += curNextNode.parent.rect.left;
                    start.y += curNextNode.parent.rect.top;
                    Vector2       end = curMouseEndPos;
                    ConnectionDef def = curNextNode.connectDef;
                    Color         c   = def != null ? def.color : Color.white;
                    NodeFlowDrawHelper.DrawLine(start, end, c);
                }
                EndWindows();
                EditorGUILayout.EndScrollView();
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }
            OnDoEnevent();
        }
        public void Update()
        {
            for (int i = 0; i < operList.Count; ++i)
            {
                OperCmdInfo cmdInfo = operList[i];
                switch (cmdInfo.cmd)
                {
                case OperCmd.NODE_ACTIVE:
                {
                    if (editorMode.mCurrent != null)
                    {
                        editorMode.mCurrent.SetNodeActive((int)cmdInfo.param, (bool)cmdInfo.param2);
                    }
                }
                break;

                case OperCmd.REMOVE_NODE:
                {
                    if (editorMode.mCurrent != null)
                    {
                        editorMode.mCurrent.RemoveNode((int)cmdInfo.param);
                    }
                }
                break;

                case OperCmd.CREATE_NODE:
                {
                    if (editorMode.mCurrent != null)
                    {
                        Vector2 pos = new Vector2(200, 100);
                        editorMode.mCurrent.CreateNode(cmdInfo.param as NodeDef, pos);
                    }
                }
                break;

                case OperCmd.CLONE_NODE:
                {
                    if (editorMode.mCurrent != null)
                    {
                        editorMode.mCurrent.CloneNode(cmdInfo.param as Node);
                    }
                }
                break;

                case OperCmd.OPEN_FILE:
                {
                    string name = (string)cmdInfo.param;
                    selectedNodeId = -1;
                    editorMode.LoadFlowByPath(name);

                    Repaint();
                }
                break;

                case OperCmd.CREATE_NEW:
                {
                    selectedNodeId = -1;
                    editorMode.CreateNewFlow();
                }
                break;

                case OperCmd.SAVE_FILE:
                {
                    if (editorMode.mCurrent != null)
                    {
                        bool needReLoad = false;
                        if (editorMode.mCurrent.name.Length == 0)
                        {
                            //to show save dalog
                            //needReLoad = true;
                            UnityEngine.Debug.LogError("文件名为空");
                        }
                        else
                        {
                            NodeFlowEditorSaver.SaveToXml(this, editorMode.mCurrent.name, editorMode.mCurrent);
                            needReLoad = true;
                        }

                        if (needReLoad)
                        {
                            if (Application.isPlaying == true)
                            {
                                editorMode.ReLoadFlow();
                                Repaint();
                            }
                            filesList.Reload(this.edtorName);
                        }
                    }
                }
                break;
                }
            }
            operList.Clear();
            if (Application.isPlaying)
            {
                editorMode.OnUpdate();
            }
        }
 public void AddCmd(OperCmdInfo info)
 {
     operList.Add(info);
 }
        //default node renderer
        public static void NodeWindow(int id)
        {
            if (curFlow == null)
            {
                return;
            }
            Node node = curFlow.GetNodeByID(id);

            if (node == null)
            {
                return;
            }
            GUI.DragWindow(new Rect(0, 0, node.rect.width, 20));
            //in
            {
                for (int i = 0; i < node.preNodeList.Count; ++i)
                {
                    PreNode pre    = node.preNodeList[i];
                    int     height = 30 + pre.inIdx * 30;
                    Rect    rect   = new Rect(20, height, 60, 30);
                    GUI.Label(rect, pre.desc);
                }
            }

            //out
            {
                for (int i = 0; i < node.nextNodeList.Count; ++i)
                {
                    NextNode next   = node.nextNodeList[i];
                    int      height = 30 + next.outIdx * 30;
                    Rect     rect   = new Rect(node.rect.width - 60, height, 60, 30);
                    GUI.Label(rect, next.desc);
                }
            }

            //seocket cell
            {
                for (int i = 0; i < node.preNodeList.Count; ++i)
                {
                    PreNode pre = node.preNodeList[i];
                    Color   c   = pre.connectDef != null ? pre.connectDef.color : Color.white;
                    GUI.color = c;
                    GUI.Box(pre.rect, "");
                }

                for (int i = 0; i < node.nextNodeList.Count; ++i)
                {
                    NextNode next = node.nextNodeList[i];
                    Color    c    = next.connectDef != null ? next.connectDef.color : Color.white;
                    GUI.color = c;
                    GUI.Box(next.rect, "");
                }
                GUI.color = Color.white;
            }
            //delete button
            if (NodeFlowEditorWindow.instance.GetSelectedNodeId() == id)
            {
                if (GUI.Button(new Rect(node.rect.width / 2 - 10, node.rect.height - 20, 20, 20), "X"))
                {
                    //del node
                    OperCmdInfo cmdInfo = new OperCmdInfo();
                    cmdInfo.cmd   = OperCmd.REMOVE_NODE;
                    cmdInfo.param = id;
                    NodeFlowEditorWindow.instance.AddCmd(cmdInfo);
                }
            }
        }