Exemple #1
0
        protected virtual void ParseConnectDef(XmlElement elm)
        {
            ConnectionDef connectDef = new ConnectionDef();

            connectDef.name = elm.GetAttribute("name");
            connectDef.desc = elm.GetAttribute("desc");

            if (elm.HasAttribute("multi_input"))
            {
                connectDef.multiInput = bool.Parse(elm.GetAttribute("multi_input"));
            }

            if (elm.HasAttribute("multi_output"))
            {
                connectDef.multiOutput = bool.Parse(elm.GetAttribute("multi_output"));
            }

            if (elm.HasAttribute("color"))
            {
                string   strColor = elm.GetAttribute("color");
                string[] rgb      = strColor.Split(',');
                Vector3  vColor   = new Vector3(float.Parse(rgb[0]), float.Parse(rgb[1]), float.Parse(rgb[2]));
                vColor          /= 255.0f;
                connectDef.color = new Color(vColor.x, vColor.y, vColor.z);
            }
            editor.connectDef.Add(connectDef);
        }
        public void BindConnection(NextNode next, PreNode prev, ConnectionDef def)
        {
            if (prev == null || next == null)
            {
                return;
            }
            for (int i = 0; i < connections.Count; ++i)
            {
                Connection connection = connections[i];

                if (connection.outId == next.parent.id &&
                    connection.inId == prev.parent.id &&
                    connection.outIdx == next.outIdx &&
                    connection.inIndex == prev.inIdx
                    )
                {
                    UnBindConnection(next, prev, connection);
                    return;
                }
            }

            if (prev.connectDef != next.connectDef)
            {
                UnityEngine.Debug.LogError("接口类型不同!");
                return;
            }

            if (prev.connectDef.multiInput == false)
            {
                if (prev.GetPortCount() >= 1)
                {
                    UnityEngine.Debug.LogError("入口连线数不能超过1");
                    return;
                }
            }

            if (next.connectDef.multiInput == false)
            {
                if (next.GetPortCount() >= 1)
                {
                    UnityEngine.Debug.LogError("出口连线数不能超过1");
                    return;
                }
            }

            Connection newConnect = new Connection();

            newConnect.connectDef = def;
            newConnect.connectDef.Init(newConnect);
            newConnect.outId   = next.parent.id;
            newConnect.outIdx  = next.outIdx;
            newConnect.outName = next.name;
            newConnect.inId    = prev.parent.id;
            newConnect.inIndex = prev.inIdx;
            newConnect.inName  = prev.name;
            AddConnection(newConnect);

            prev.AddPort(next.parent.id, next.outIdx);
            next.AddPort(prev.parent.id, prev.inIdx);
        }
 void BindConnection(NextNode next, PreNode prev, ConnectionDef def)
 {
     if (editorMode.mCurrent == null)
     {
         return;
     }
     editorMode.mCurrent.BindConnection(next, prev, def);
 }
Exemple #4
0
        protected virtual void ParseConnection(XmlElement elm, NodeFlow flow)
        {
            string        connectName = elm.GetAttribute("name");
            ConnectionDef def         = editor.GetConnectionDef(connectName);

            if (def == null)
            {
                UnityEngine.Debug.LogError("can not prase connect:" + connectName);
                return;
            }
            int      fromNode      = int.Parse(elm.GetAttribute("from_node"));
            string   fromOutput    = elm.GetAttribute("from_output");
            Node     outNode       = flow.GetNodeByID(fromNode);
            int      fromOutputIdx = outNode.GetNextNodeIdxByName(fromOutput);
            NextNode nextNode      = outNode.nextNodeList[fromOutputIdx];

            int     toNode     = int.Parse(elm.GetAttribute("to_node"));
            string  toInput    = elm.GetAttribute("to_input");
            Node    inNode     = flow.GetNodeByID(toNode);
            int     toInputIdx = inNode.GetPreNodeIdxByName(toInput);
            PreNode preNode    = inNode.preNodeList[toInputIdx];

            flow.BindConnection(nextNode, preNode, def);
        }
        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();
        }