コード例 #1
0
        public static void DrawConnection(Connection connection)
        {
            if (curFlow == null)
            {
                return;
            }
            Node outNode = curFlow.GetNodeByID(connection.outId);

            if (outNode == null)
            {
                return;
            }
            Node inNode = curFlow.GetNodeByID(connection.inId);

            if (inNode == null)
            {
                return;
            }
            NextNode next  = outNode.nextNodeList[connection.outIdx];
            PreNode  pre   = inNode.preNodeList[connection.inIndex];
            Vector2  start = next.rect.center;

            start.x += outNode.rect.left;
            start.y += outNode.rect.top;
            Vector2 end = pre.rect.center;

            end.x += inNode.rect.left;
            end.y += inNode.rect.top;
            DrawLine(start, end, connection.color);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
 void BindConnection(NextNode next, PreNode prev, ConnectionDef def)
 {
     if (editorMode.mCurrent == null)
     {
         return;
     }
     editorMode.mCurrent.BindConnection(next, prev, def);
 }
コード例 #4
0
        public virtual void Init(Node node)
        {
            node.name  = this.name;
            node.desc  = this.desc;
            node.type  = this.type;
            node.color = this.color;
            //input
            foreach (Input o in this.input)
            {
                PreNode preNode = new PreNode(node);
                preNode.inIdx       = node.preNodeList.Count;
                preNode.name        = o.name;
                preNode.desc        = o.desc;
                preNode.connectType = o.connectType;
                preNode.connectDef  = NodeFlowEditorWindow.instance.GetConnectionDef(preNode.connectType);
                node.preNodeList.Add(preNode);
            }
            //output
            foreach (Output o in this.output)
            {
                NextNode nextNode = new NextNode(node);
                nextNode.outIdx      = node.nextNodeList.Count;
                nextNode.name        = o.name;
                nextNode.desc        = o.desc;
                nextNode.connectType = o.connectType;
                nextNode.connectDef  = NodeFlowEditorWindow.instance.GetConnectionDef(nextNode.connectType);
                node.nextNodeList.Add(nextNode);
            }

            //param
            foreach (Param p in this.param)
            {
                ParamProperty nodePro = new ParamProperty();
                p.Init(nodePro);
                node.property.Add(nodePro);
            }

            //event
            foreach (EventInfo evt  in this.events)
            {
                EventProperty eventPro = new EventProperty();
                eventPro.name         = evt.name;
                eventPro.strValue     = "";
                eventPro.editorParams = evt.editorParams;
                eventPro.eventDef     = null;
                eventPro.desc         = evt.desc;
                node.eventProperty.Add(eventPro);
            }
        }
コード例 #5
0
        public void ResetSize()
        {
            //sise
            rect.width = 160;
            int maxNum = preNodeList.Count > nextNodeList.Count ? preNodeList.Count : nextNodeList.Count;

            rect.height = 40 + maxNum * 30;

            float socketCellSize = 20.0f;

            //in pos
            for (int i = 0; i < preNodeList.Count; ++i)
            {
                PreNode preNode = preNodeList[i];
                preNode.rect = new Rect(0, 30 + preNode.inIdx * 30, socketCellSize, socketCellSize);
            }

            //out pos
            for (int i = 0; i < nextNodeList.Count; ++i)
            {
                NextNode nextNode = nextNodeList[i];
                nextNode.rect = new Rect(rect.width - socketCellSize, 30 + nextNode.outIdx * 30, socketCellSize, socketCellSize);
            }
        }
コード例 #6
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);
        }
コード例 #7
0
        void OnDoEnevent()
        {
            Event currentEvent = Event.current;

            if (currentEvent.button == 0)
            {
                Vector2 vMousePos = Event.current.mousePosition;

                if (currentEvent.type == EventType.MouseDown)
                {
                    //只做编辑区域内的点击判断
                    if (IsMousePosInNodeEditorView(vMousePos))
                    {
                        if (curNextNode == null)
                        {
                            curNextNode = GetNextNodeSocket(vMousePos);

                            if (curNextNode != null)
                            {
                                curMouseEndPos = MousePosToViewPos(vMousePos);
                                Repaint();
                            }
                        }
                        else
                        {
                            NextNode nextNode = GetNextNodeSocket(vMousePos);

                            if (nextNode != curNextNode)
                            {
                                PreNode preNode = GetNodeInSocket(vMousePos);
                                //bind connection
                                BindConnection(curNextNode, preNode, curNextNode.connectDef);
                                curNextNode = null;
                                Repaint();
                            }
                        }
                    }
                }
                else if (currentEvent.type == EventType.MouseDrag)
                {
                    if (curNextNode != null)
                    {
                        curMouseEndPos = MousePosToViewPos(vMousePos);
                        Repaint();
                    }
                }
                else if (currentEvent.type == EventType.MouseUp)
                {
                    if (IsMousePosInNodeEditorView(vMousePos))
                    {
                        if (curNextNode != null)
                        {
                            PreNode preNode = GetNodeInSocket(vMousePos);
                            if (preNode != null)
                            {
                                //bind connection
                                BindConnection(curNextNode, preNode, curNextNode.connectDef);
                                curNextNode = null;
                            }
                        }
                        else
                        {
                            selectedNodeId = GetSelectNodeId(vMousePos);
                        }
                        Repaint();
                    }
                }
            }

            if (EventType.ContextClick == currentEvent.type)
            {
                Vector2 vMousePos = currentEvent.mousePosition;
                selectedNodeId = GetSelectNodeId(vMousePos);
                curNextNode    = null;

                if (selectedNodeId > -1)
                {
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("Clone"), false, CloneCmd, selectedNodeId);
                    menu.AddSeparator("");
                    menu.AddItem(new GUIContent("Delete"), false, DeleteCmd, selectedNodeId);
                    menu.ShowAsContext();
                    currentEvent.Use();
                }
                Repaint();
            }

            if (selectedNodeId > -1)
            {
                if (currentEvent.isKey)
                {
                    Repaint();
                    string name = GUI.GetNameOfFocusedControl();
                    int    idx  = 0;
                    if (!int.TryParse(name, out idx))
                    {
                        return;
                    }
                    if (currentEvent.keyCode == KeyCode.C && currentEvent.control)
                    {
                        string value = editorMode.CopyProperty(selectedNodeId, name);

                        textEditor.text = value;
                        textEditor.SelectAll();
                        textEditor.Copy();
                    }
                    if (currentEvent.keyCode == KeyCode.V && currentEvent.control)
                    {
                        textEditor.text = "";
                        textEditor.Paste();
                        string value = textEditor.text;
                        editorMode.PasteProperty(selectedNodeId, name, value);
                    }
                    Repaint();
                }
            }
        }
コード例 #8
0
        //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);
                }
            }
        }
コード例 #9
0
 public void UnBindConnection(NextNode next, PreNode prev, Connection connect)
 {
     connections.Remove(connect);
     prev.RemovePort(next.parent.id, next.outIdx);
     next.RemovePort(prev.parent.id, prev.inIdx);
 }