Esempio n. 1
0
        private static InputPortConfigInfo ConvertToInputPortInfo(InputPortEditorView inputPort)
        {
            InputPortConfigInfo inputPortConfigInfo = new InputPortConfigInfo();

            InputPortReflectionInfo inputPortReflectionInfo = inputPort.inputPortReflectionInfo;

            inputPortConfigInfo.portName = inputPortReflectionInfo.inputPortAttribute.portName;

            if (inputPort.connectedPortList.Count > 0)
            {
                inputPortConfigInfo.targetNodeId = inputPort.connectedPortList[0].NodeView.NodeId;
                OutputPortEditorView outputPortView = inputPort.connectedPortList[0] as OutputPortEditorView;
                if (outputPortView == null)
                {
                    Debug.LogErrorFormat("节点{0}的input端口{1} 连接的接口类型不是OutputPortEditorView", inputPort.NodeView.NodeId,
                                         inputPort.portId);
                    return(null);
                }

                inputPortConfigInfo.targetPortName = outputPortView.outputPortReflectionInfo.PortName;
            }
            else
            {
                inputPortConfigInfo.targetNodeId   = -1;
                inputPortConfigInfo.targetPortName = string.Empty;

                inputPortConfigInfo.nodeVariableGenericTypeName = inputPortReflectionInfo.inputValueType.FullName;
                inputPortConfigInfo.nodeVariableValue           = inputPortReflectionInfo.GetNodeVariableValueString();
            }

            return(inputPortConfigInfo);
        }
Esempio n. 2
0
        private static NodeConfigInfo ConvertToNodeInfo(NodeEditorView nodeView)
        {
            NodeConfigInfo nodeConfigInfo = new NodeConfigInfo();

            nodeConfigInfo.nodeId            = nodeView.NodeId;
            nodeConfigInfo.positionInGraph   = nodeView.PositionInGraph;
            nodeConfigInfo.nodeClassTypeName = nodeView.ReflectionInfo.Type.FullName;

            nodeConfigInfo.flowOutPortInfoList = new List <FlowOutPortConfigInfo>();
            nodeConfigInfo.inputPortInfoList   = new List <InputPortConfigInfo>();

            //flow out info
            for (int i = 0; i < nodeView.flowOutPortViews.Length; i++)
            {
                FlowOutPortEditorView flowOutPort = nodeView.flowOutPortViews[i];
                nodeConfigInfo.flowOutPortInfoList.Add(ConvertToFlowOutPortInfo(flowOutPort));
            }

            //input info
            for (int i = 0; i < nodeView.inputPortViewList.Count; i++)
            {
                InputPortEditorView inputPort = nodeView.inputPortViewList[i];
                nodeConfigInfo.inputPortInfoList.Add(ConvertToInputPortInfo(inputPort));
            }

            return(nodeConfigInfo);
        }
Esempio n. 3
0
        /// <summary>
        /// 检查input port和output port连线的合法性
        /// </summary>
        public void CheckIOPortConnectionValidate()
        {
            for (int i = 0; i < inputPortViewList.Count; i++)
            {
                InputPortEditorView inputPortView = inputPortViewList[i];
                if (inputPortView.connectedPortList.Count == 1)
                {
                    if (!ConnectionLineView.CheckPortsCanLine(inputPortView, inputPortView.connectedPortList[0]))
                    {
                        graph.data.FindConnectionByPortsAndRemoveIt(inputPortView, inputPortView.connectedPortList[0]);
                    }
                }
            }

            for (int i = 0; i < outputPortViewList.Count; i++)
            {
                OutputPortEditorView outputPortView = outputPortViewList[i];
                for (int j = 0; j < outputPortView.connectedPortList.Count; j++)
                {
                    InputPortEditorView connectedInputPortView = outputPortView.connectedPortList[j] as InputPortEditorView;
                    if (connectedInputPortView == null)
                    {
                        continue;
                    }

                    if (!ConnectionLineView.CheckPortsCanLine(outputPortView, connectedInputPortView))
                    {
                        graph.data.FindConnectionByPortsAndRemoveIt(outputPortView, connectedInputPortView);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 检查两个端口是否可以连接
        /// </summary>
        /// <param name="portA"></param>
        /// <param name="portB"></param>
        /// <returns></returns>
        public static bool CheckPortsCanLine(PortEditorView portA, PortEditorView portB)
        {
            if (portA == null || portB == null)
            {
                return(false);
            }

            if (portA.FlowType == portB.FlowType)
            {
                return(false);
            }

            if (portA.NodeView == portB.NodeView)
            {
                return(false);
            }

            PortEditorView flowOutPortView = portA.FlowType == FlowType.Out ? portA : portB;
            PortEditorView flowInPortView  = portA.FlowType == FlowType.In ? portA : portB;

            //两边接口是流出和流入
            if (flowOutPortView is FlowOutPortEditorView && flowInPortView is FlowInPortEditorView)
            {
                return(true);
            }

            //两边接口是Output和Input
            OutputPortEditorView outputPortView = flowOutPortView as OutputPortEditorView;
            InputPortEditorView  inputPortView  = flowInPortView as InputPortEditorView;

            if (outputPortView == null || inputPortView == null)
            {
                Debug.LogError("端口连接类型错误");
                return(false);
            }

            if (outputPortView.PortValueType != inputPortView.PortValueType)
            {
                return(false);
            }

            //存取技能变量的端口,都不允许连接
            if (inputPortView.inputPortReflectionInfo.inputValueType == typeof(VariableWrapper))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// 当节点对应的是<see cref="FlatNode.Runtime.GetVariableNode"/> 或者 <see cref="FlatNode.Runtime.SetVariableNode"/> 时
        /// 他们接口的类型需要显示为对应类型。
        /// 还要重新计算节点Rect的大小
        /// </summary>
        /// <param name="variableType"></param>
        /// <param name="needRecheckConnection"></param>
        public void UpdateGraphVariableNodeIOPortType(Type variableType, bool needRecheckConnection)
        {
            if (ReflectionInfo.Type == typeof(GetVariableNode))
            {
                //第一个input port是选择要读取哪一个变量
                InputPortEditorView inputPortView = inputPortViewList[0];
                inputPortView.overridePortType = variableType;

                //第一个output port是要输出选择的变量
                OutputPortEditorView outputPortView = outputPortViewList[0];
                outputPortView.overridePortType = variableType;

                CalculateNodeSize();

                if (needRecheckConnection)
                {
                    CheckIOPortConnectionValidate();
                }
            }
            else if (ReflectionInfo.Type == typeof(SetVariableNode))
            {
                //第一个input port是选择要存储到哪个变量
                InputPortEditorView setVariableInputPort = inputPortViewList[0];
                setVariableInputPort.overridePortType = variableType;

                //第二个input port是接收要存储的值
                InputPortEditorView valueVariableInputPort = inputPortViewList[1];
                valueVariableInputPort.overridePortType = variableType;

                //该节点没有output port

                CalculateNodeSize();

                if (needRecheckConnection)
                {
                    CheckIOPortConnectionValidate();
                }
            }
        }
Esempio n. 6
0
        void ProcessEvent(Event e)
        {
            Vector2 windowMousePosition = e.mousePosition;
            Vector2 zoomedMousePosition = NonZoomedWindowPositionToZoomedWindowPosition(windowMousePosition);

            List <NodeEditorView>     nodeViewList           = data.CurrentNodeList;
            List <ConnectionLineView> connectionLineViewList = data.CurrentConnectionLineList;

            bool hasHoveredNodeOrPort = false;
            //如果在输入标签上,要屏蔽与注释框的交互
            bool hasHoverdNodeInputLabel = false;

            for (int i = 0; i < nodeViewList.Count; i++)
            {
                NodeEditorView nodeView = nodeViewList[i];

                #region 提示框鼠标悬浮显示

                //在没有任何操作的时候,才显示tips框
                if (controlType == ControlType.None && !hasHoveredNodeOrPort)
                {
                    if (nodeView.NodeNameRect.Contains(zoomedMousePosition))
                    {
                        //reset time
                        if (currentHoverNodeView != nodeView)
                        {
                            startHoverdTime = EditorApplication.timeSinceStartup;
                        }

                        hasHoveredNodeOrPort = true;
                        currentHoverNodeView = nodeView;
                        currentHoverPortView = null;
                    }

                    if (!hasHoveredNodeOrPort)
                    {
                        List <PortEditorView> allPortList = nodeView.allPortList;
                        for (int j = 0; j < allPortList.Count; j++)
                        {
                            PortEditorView portView = allPortList[j];
                            if (portView.portViewRect.Contains(zoomedMousePosition))
                            {
                                //reset time
                                if (currentHoverPortView != portView)
                                {
                                    startHoverdTime = EditorApplication.timeSinceStartup;
                                }

                                hasHoveredNodeOrPort = true;
                                currentHoverPortView = portView;
                                currentHoverNodeView = null;

                                break;
                            }

                            if (portView is InputPortEditorView)
                            {
                                InputPortEditorView inputView = portView as InputPortEditorView;
                                if (inputView.IsInputLabelContains(zoomedMousePosition))
                                {
                                    hasHoverdNodeInputLabel = true;
                                }
                            }
                        }
                    }
                }

                #endregion

                if (controlType == ControlType.None && e.type == EventType.MouseDown && e.button == 0)
                {
                    //点击开始拖拽连线
                    List <PortEditorView> allPortList = nodeView.allPortList;
                    for (int j = 0; j < allPortList.Count; j++)
                    {
                        PortEditorView portView = allPortList[j];
                        if (portView.connectionCircleRect.Contains(zoomedMousePosition))
                        {
                            controlType      = ControlType.DraggingConnection;
                            draggingLineView = new ConnectionLineView(portView);
                            draggingLineView.SetEndPos(zoomedMousePosition);
                            e.Use();
                            break;
                        }
                    }

                    //开始拖拽节点
                    if (nodeView.viewRect.Contains(zoomedMousePosition))
                    {
                        if (data.selectedNodeList.Contains(nodeView))
                        {
                            controlType = ControlType.DraggingMultiNodes;
                        }
                        else
                        {
                            controlType      = ControlType.DraggingNode;
                            draggingNodeView = nodeView;
                            data.PutNodeToListTail(i);
                        }

                        e.Use();
                        break;
                    }
                }

                //节点右键菜单
                if (controlType == ControlType.None && e.type == EventType.MouseDown && e.button == 1)
                {
                    if (nodeView.viewRect.Contains(zoomedMousePosition))
                    {
                        OpenNodeGenericMenu(nodeView, e.mousePosition);
                        e.Use();
                        break;
                    }
                }
            }

            if (currentHoverConnectionLineView != null)
            {
                currentHoverConnectionLineView.SetHovering(false);
            }

            currentHoverConnectionLineView = null;
            if (controlType == ControlType.None)
            {
                //和连接线的交互
                for (int i = 0; i < connectionLineViewList.Count; i++)
                {
                    ConnectionLineView connectionLineView = connectionLineViewList[i];
                    if (connectionLineView.IsPositionCloseToLine(zoomedMousePosition))
                    {
                        currentHoverConnectionLineView = connectionLineView;
                        currentHoverConnectionLineView.SetHovering(true);

                        //右键点击连线
                        if (e.type == EventType.MouseDown && e.button == 1)
                        {
                            OpenConnectionLineGenericMenu(connectionLineView, e.mousePosition);
                            e.Use();
                        }

                        break;
                    }
                }
            }

            if (!hasHoveredNodeOrPort)
            {
                currentHoverPortView = null;
                currentHoverNodeView = null;
            }

            if (controlType == ControlType.DraggingNode && e.type == EventType.MouseDrag && e.button == 0)
            {
                draggingNodeView.Drag(e.delta / data.GraphZoom);
                e.Use();
            }

            if (controlType == ControlType.DraggingNode && e.type == EventType.MouseUp && e.button == 0)
            {
                controlType      = ControlType.None;
                draggingNodeView = null;
                e.Use();
            }

            if (controlType == ControlType.DraggingMultiNodes && e.type == EventType.MouseDrag && e.button == 0)
            {
                for (int i = 0; i < data.selectedNodeList.Count; i++)
                {
                    data.selectedNodeList[i].Drag(e.delta / data.GraphZoom);
                }

                e.Use();
            }

            if (controlType == ControlType.DraggingMultiNodes && e.type == EventType.MouseUp && e.button == 0)
            {
                controlType = ControlType.None;

                e.Use();
            }

            if (controlType == ControlType.DraggingConnection && e.type == EventType.MouseDrag && e.button == 0)
            {
                if (draggingLineView != null)
                {
                    draggingLineView.SetEndPos(zoomedMousePosition);
                }
            }

            if (controlType == ControlType.DraggingConnection && e.type == EventType.MouseUp && e.button == 0)
            {
                if (draggingLineView != null)
                {
                    bool createNewConnection = false;
                    //检查是否有连接
                    for (int i = 0; i < nodeViewList.Count; i++)
                    {
                        NodeEditorView        nodeView    = nodeViewList[i];
                        List <PortEditorView> allPortList = nodeView.allPortList;
                        for (int j = 0; j < allPortList.Count; j++)
                        {
                            PortEditorView portView = allPortList[j];

                            if (portView.connectionCircleRect.Contains(zoomedMousePosition))
                            {
                                if (ConnectionLineView.CheckPortsCanLine(draggingLineView.draggingPort, portView))
                                {
                                    ConnectionLineView newConnectionLine =
                                        new ConnectionLineView(draggingLineView.draggingPort, portView, data);
                                    data.connectionLineList.Add(newConnectionLine);
                                    data.CurrentConnectionLineList.Add(newConnectionLine);

                                    createNewConnection = true;
                                    break;
                                }
                            }
                        }

                        if (createNewConnection)
                        {
                            break;
                        }
                    }

                    draggingLineView.Dispose();
                }

                draggingLineView = null;
                controlType      = ControlType.None;
                e.Use();
            }

            //中键拖动面板
            if (e.type == EventType.MouseDrag && e.button == 2)
            {
                data.GraphOffset += e.delta / data.GraphZoom;
                e.Use();

                if (draggingLineView != null)
                {
                    draggingLineView.SetEndPos(zoomedMousePosition);
                }
            }

            //滚轮控制缩放
            if (e.type == EventType.ScrollWheel)
            {
                data.GraphZoom -= e.delta.y / GraphEditorData.GraphZoomSpeed;
                data.GraphZoom  = Mathf.Clamp(data.GraphZoom, GraphEditorData.MinGraphZoom, GraphEditorData.MaxGraphZoom);
                e.Use();

                if (draggingLineView != null)
                {
                    draggingLineView.SetEndPos(zoomedMousePosition);
                }
            }


            //记录左ctrl按下状态
            if (e.type == EventType.KeyDown && e.keyCode == KeyCode.LeftControl)
            {
                isCtrlDown = true;
            }

            //记录左ctrl按下状态
            if (e.type == EventType.KeyUp && e.keyCode == KeyCode.LeftControl)
            {
                isCtrlDown = false;

                if (controlType == ControlType.DraggingNewCommentBox)
                {
                    controlType = ControlType.None;
                }
            }

            //开始拖拽新的注释框
            if (isCtrlDown && controlType == ControlType.None && e.type == EventType.MouseDown && e.button == 0)
            {
                controlType = ControlType.DraggingNewCommentBox;
                startDraggingCommentBoxGraphPosition = WindowPositionToGraphPosition(windowMousePosition);
                endDraggingCommentBoxGraphPosition   = startDraggingCommentBoxGraphPosition;

                e.Use();
            }

            //更新新的注释框
            if (controlType == ControlType.DraggingNewCommentBox && e.type == EventType.MouseDrag && e.button == 0)
            {
                endDraggingCommentBoxGraphPosition = WindowPositionToGraphPosition(windowMousePosition);
                e.Use();
            }

            //结束新的注释框
            if (isCtrlDown && controlType == ControlType.DraggingNewCommentBox && e.type == EventType.MouseUp && e.button == 0)
            {
                controlType = ControlType.None;

                CommentBoxView newCommentBox = new CommentBoxView(this, startDraggingCommentBoxGraphPosition,
                                                                  endDraggingCommentBoxGraphPosition);
                data.CurrentCommentBoxViewList.Add(newCommentBox);

                e.Use();
            }

            //注释框操作
            if (data.CurrentCommentBoxViewList.Count > 0 && !hasHoverdNodeInputLabel)
            {
                for (int i = 0; i < data.CurrentCommentBoxViewList.Count; i++)
                {
                    CommentBoxView commentBoxView = data.CurrentCommentBoxViewList[i];

                    //右键点击注释框
                    if (controlType == ControlType.None && e.type == EventType.MouseDown && e.button == 1)
                    {
                        if (commentBoxView.Contains(zoomedMousePosition))
                        {
                            OpenCommentBoxGenericMenu(commentBoxView, e.mousePosition);
                            e.Use();
                            break;
                        }
                    }

                    //拖拽编辑注释区域大小
                    if (controlType == ControlType.None && (e.type != EventType.Layout || e.type != EventType.Repaint))
                    {
                        CommentBoxView.BoxEdge boxEdge = commentBoxView.AtEdge(zoomedMousePosition);
                        if (boxEdge != CommentBoxView.BoxEdge.None)
                        {
                            MouseCursor cursorMode =
                                (boxEdge == CommentBoxView.BoxEdge.Left || boxEdge == CommentBoxView.BoxEdge.Right)
                                    ? MouseCursor.ResizeHorizontal
                                    : MouseCursor.ResizeVertical;
                            EditorGUIUtility.AddCursorRect(guiRect, cursorMode);

                            //开始拖拽扩大
                            if (e.type == EventType.MouseDown && e.button == 0)
                            {
                                resizingCommentEdge = boxEdge;
                                resizingCommentBox  = commentBoxView;
                                controlType         = ControlType.ResizingCommentBox;

                                e.Use();
                            }

                            break;
                        }
                    }

                    //双击编辑注释
                    if ((controlType == ControlType.None || controlType == ControlType.DraggingCommentBox) &&
                        e.type == EventType.MouseDown && e.button == 0)
                    {
                        if (commentBoxView.Contains(zoomedMousePosition))
                        {
                            if (lastClickCommentBox == null || lastClickCommentBox != commentBoxView)
                            {
//                                Debug.Log("click once");
                                //一次点击可能是要拖拽了
                                controlType          = ControlType.DraggingCommentBox;
                                lastClickCommentBox  = commentBoxView;
                                draggingCommentBox   = commentBoxView;
                                lastClickCommentTime = EditorApplication.timeSinceStartup;
                                e.Use();
                                break;
                            }
                            else if (lastClickCommentBox == commentBoxView)
                            {
                                double currentTime = EditorApplication.timeSinceStartup;
                                if (currentTime - lastClickCommentTime <= 0.3f)
                                {
//                                    Debug.Log("click twice");
                                    controlType = ControlType.EditingComment;
                                    lastClickCommentBox.EnableEditComment(true);
                                    editingCommentBox   = lastClickCommentBox;
                                    lastClickCommentBox = null;
                                    e.Use();
                                    break;
                                }
                                else
                                {
//                                    Debug.Log("click twice failed");
                                    lastClickCommentBox = null;
                                }
                            }
                        }
                    }
                }
            }

            //右键点击面板
            if (e.type == EventType.MouseDown && e.button == 1)
            {
                OpenGraphGenericMenu(e.mousePosition);
                e.Use();
            }

            //改变注释框大小的时候,改变鼠标图标
            if (controlType == ControlType.ResizingCommentBox)
            {
                MouseCursor cursorMode =
                    (resizingCommentEdge == CommentBoxView.BoxEdge.Left || resizingCommentEdge == CommentBoxView.BoxEdge.Right)
                        ? MouseCursor.ResizeHorizontal
                        : MouseCursor.ResizeVertical;
                EditorGUIUtility.AddCursorRect(guiRect, cursorMode);
            }

            //编辑注释框大小
            if (controlType == ControlType.ResizingCommentBox && e.type == EventType.MouseDrag && e.button == 0)
            {
                if (resizingCommentBox != null)
                {
                    if (resizingCommentEdge != CommentBoxView.BoxEdge.None)
                    {
                        resizingCommentBox.Resizing(resizingCommentEdge, e.delta / data.GraphZoom);
                        e.Use();
                    }
                }
            }

            //停止编辑注释框大小
            if (controlType == ControlType.ResizingCommentBox && e.type == EventType.MouseUp && e.button == 0)
            {
                controlType         = ControlType.None;
                resizingCommentBox  = null;
                resizingCommentEdge = CommentBoxView.BoxEdge.None;
                e.Use();
            }

            //拖拽注释框
            if (controlType == ControlType.DraggingCommentBox && draggingCommentBox != null && e.type == EventType.MouseDrag &&
                e.button == 0)
            {
                if (draggingCommentBox.Contains(zoomedMousePosition))
                {
                    draggingCommentBox.Drag(data.CurrentNodeList, e.delta / data.GraphZoom);
                    e.Use();
                }
            }

            //停止拖拽注释框
            if (controlType == ControlType.DraggingCommentBox && draggingCommentBox != null && e.type == EventType.MouseUp &&
                e.button == 0)
            {
                draggingCommentBox = null;
                controlType        = ControlType.None;
                e.Use();
            }

            //停止编辑注释框
            if (e.type == EventType.MouseDown)
            {
                if (controlType == ControlType.EditingComment)
                {
                    if (!editingCommentBox.Contains(zoomedMousePosition))
                    {
                        controlType = ControlType.None;
                        editingCommentBox.EnableEditComment(false);
                        editingCommentBox = null;
                        GUI.FocusControl(null);
                        e.Use();
                    }
                }
                else
                {
                    data.ClearSelectedNode();
                    GUI.FocusControl(null);
                }
            }

            //开始多选框
            if (controlType == ControlType.None && e.type == EventType.MouseDrag && e.button == 0)
            {
                startMultiSelectionPos = e.mousePosition;
                controlType            = ControlType.DraggingMultiSelection;
                e.Use();
            }

            //更新多选框
            if (controlType == ControlType.DraggingMultiSelection)
            {
                Rect multiSelectionRect = new Rect();
                multiSelectionRect.position = NonZoomedWindowPositionToZoomedWindowPosition(startMultiSelectionPos);
                multiSelectionRect.max      = NonZoomedWindowPositionToZoomedWindowPosition(e.mousePosition);
                data.UpdateSelectedNode(multiSelectionRect);
            }

            //结束多选框
            if (controlType == ControlType.DraggingMultiSelection && e.type == EventType.MouseUp && e.button == 0)
            {
                controlType = ControlType.None;
                e.Use();
            }

            //排除掉鼠标移出去之后,多选框还会继续拖拽的问题
            if (!guiRect.Contains(e.mousePosition) && e.type != EventType.Layout && e.type != EventType.Repaint)
            {
                if (controlType == ControlType.DraggingMultiSelection)
                {
                    controlType = ControlType.None;
                    e.Use();
                }
            }
        }
Esempio n. 7
0
        private static void UpdateNodeViewData(NodeConfigInfo nodeConfigInfo, NodeEditorView nodeView, GraphEditorData data)
        {
            //flow in port--处理流出节点的时候顺便就处理了

            //flow out port
            for (int i = 0; i < nodeConfigInfo.flowOutPortInfoList.Count; i++)
            {
                FlowOutPortConfigInfo flowOutPortConfigInfo = nodeConfigInfo.flowOutPortInfoList[i];
                FlowOutPortEditorView flowOutPortView       =
                    GetFlowOutPortViewByPortName(nodeView.flowOutPortViews, flowOutPortConfigInfo.flowOutPortName);
                if (flowOutPortView == null)
                {
                    Debug.LogFormat("节点{0}中找不到流出端口 <{1}> 了,该端口的连接被忽略", nodeView.ReflectionInfo.Type,
                                    flowOutPortConfigInfo.flowOutPortName);
                    continue;
                }

                for (int j = 0; j < flowOutPortConfigInfo.targetNodeList.Count; j++)
                {
                    int            targetNodeId   = flowOutPortConfigInfo.targetNodeList[j];
                    NodeEditorView targetNodeView = data.GetNode(targetNodeId);
                    if (targetNodeView == null)
                    {
                        Debug.LogErrorFormat("无法找到节点{0},可能是配置损坏/更改了类名...", targetNodeId);
                        continue;
                    }

                    if (targetNodeView.flowInPortView == null)
                    {
                        Debug.LogErrorFormat("节点类型{0}没有流入节点,是否节点性质发生了改变?", nodeView.ReflectionInfo.Type.FullName);
                        continue;
                    }

                    ConnectionLineView connectionLineView =
                        new ConnectionLineView(flowOutPortView, targetNodeView.flowInPortView, data);
                    data.connectionLineList.Add(connectionLineView);
                }
            }

            //output port -- 不用配置

            //input port
            for (int i = 0; i < nodeConfigInfo.inputPortInfoList.Count; i++)
            {
                InputPortConfigInfo inputPortConfigInfo = nodeConfigInfo.inputPortInfoList[i];
                InputPortEditorView inputPortView       =
                    GetInputPortViewByPortName(nodeView.inputPortViewList, inputPortConfigInfo.portName);

                if (inputPortView == null)
                {
                    Debug.LogFormat("节点{0}中无法找到接口名字为 <{1}> 的NodeInputVariable Field,该接口配置被跳过",
                                    nodeView.ReflectionInfo.Type.FullName, inputPortConfigInfo.portName);
                    continue;
                }

                //没有连接到其他节点的情况
                if (string.IsNullOrEmpty(inputPortConfigInfo.targetPortName))
                {
                    //设置默认值
                    Type valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName);
                    if (valueType == null)
                    {
                        valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName + ",UnityEngine");
                        if (valueType == null)
                        {
                            valueType = Type.GetType(inputPortConfigInfo.nodeVariableGenericTypeName + ",Assembly-CSharp");
                        }
                    }

                    if (valueType == null)
                    {
                        Debug.LogErrorFormat("工程中找不到类型: {0}", inputPortConfigInfo.nodeVariableGenericTypeName);
                        continue;
                    }

                    SetNodeInputVariableValue(inputPortView.inputPortReflectionInfo, valueType,
                                              inputPortConfigInfo.nodeVariableValue, nodeView);
                }
                //连接到其他节点的情况
                else
                {
                    NodeEditorView connectedToNodeView = data.GetNode(inputPortConfigInfo.targetNodeId);
                    if (connectedToNodeView == null)
                    {
                        Debug.LogErrorFormat("节点 {0} 的input接口 {1} 找不到连接的节点{2}", nodeView.NodeId, inputPortConfigInfo.portName,
                                             inputPortConfigInfo.targetNodeId);
                        continue;
                    }

                    OutputPortEditorView connectedToOutputPortView =
                        GetOutputPortViewByPortName(connectedToNodeView.outputPortViewList, inputPortConfigInfo.targetPortName);
                    if (connectedToOutputPortView == null)
                    {
                        Debug.LogFormat("找不到节点{0}中 接口名字为 <{1}> 的output接口,该接口的连接被跳过", connectedToNodeView.NodeId,
                                        inputPortConfigInfo.targetPortName);
                        continue;
                    }

                    ConnectionLineView connectionLineView =
                        new ConnectionLineView(inputPortView, connectedToOutputPortView, data);
                    data.connectionLineList.Add(connectionLineView);
                }
            }
        }
Esempio n. 8
0
        private static Offset <NodeInputFieldInfo> ConvertToRuntimeInputPortInfo(FlatBufferBuilder fbb, InputPortEditorView inputPortView)
        {
            InputPortReflectionInfo inputPortReflectionInfo = inputPortView.inputPortReflectionInfo;

            StringOffset fieldNameOffset =
                fbb.CreateString(inputPortView.inputPortReflectionInfo.nodeInputVariableFieldInfo.Name);
            StringOffset inputValueTypeName = fbb.CreateString(inputPortReflectionInfo.inputValueType.FullName);

            if (inputPortView.connectedPortList.Count > 0)
            {
                NodeInputFieldInfo.StartNodeInputFieldInfo(fbb);
                NodeInputFieldInfo.AddTargetNodeId(fbb, inputPortView.connectedPortList[0].NodeView.NodeId);
                NodeInputFieldInfo.AddTargetPortId(fbb, inputPortView.connectedPortList[0].portId);
            }
            else
            {
                StringOffset inputValueString = fbb.CreateString(inputPortReflectionInfo.GetNodeVariableValueString());

                NodeInputFieldInfo.StartNodeInputFieldInfo(fbb);
                NodeInputFieldInfo.AddTargetNodeId(fbb, -1);
                NodeInputFieldInfo.AddTargetPortId(fbb, -1);
                NodeInputFieldInfo.AddValueString(fbb, inputValueString);
            }

            NodeInputFieldInfo.AddValueTypeName(fbb, inputValueTypeName);
            NodeInputFieldInfo.AddFieldName(fbb, fieldNameOffset);
            return(NodeInputFieldInfo.EndNodeInputFieldInfo(fbb));
        }
Esempio n. 9
0
        public NodeEditorView(Vector2 graphPosition, GraphEditorWindow graph, int nodeId, NodeReflectionInfo reflectionInfo)
        {
            this.graph          = graph;
            this.NodeId         = nodeId;
            this.ReflectionInfo = reflectionInfo;

            PositionInGraph  = graphPosition;
            PositionInWindow = graph.GraphPositionToWindowPosition(graphPosition);

            viewRect = new Rect(Vector2.zero, new Vector2(200, 400));

            allPortList        = new List <PortEditorView>();
            inputPortViewList  = new List <InputPortEditorView>();
            outputPortViewList = new List <OutputPortEditorView>();

            leftPortLayoutHelper  = new PortLayoutHelper();
            rightPortLayoutHelper = new PortLayoutHelper();

            if (reflectionInfo.HasFlowInPort)
            {
                flowInPortView        = new FlowInPortEditorView(this);
                flowInPortView.portId = 0;
                allPortList.Add(flowInPortView);
            }

            if (reflectionInfo.flowOutPortDefineAttributes.Length > 0)
            {
                flowOutPortViews = new FlowOutPortEditorView[reflectionInfo.flowOutPortDefineAttributes.Length];
                for (int i = 0; i < flowOutPortViews.Length; i++)
                {
                    flowOutPortViews[i]        = new FlowOutPortEditorView(this, reflectionInfo.flowOutPortDefineAttributes[i]);
                    flowOutPortViews[i].portId = i;
                    allPortList.Add(flowOutPortViews[i]);
                }
            }
            else
            {
                flowOutPortViews = new FlowOutPortEditorView[0];
            }

            List <InputPortReflectionInfo> inputPortReflectionInfos = reflectionInfo.inputPortInfoList;

            for (int i = 0; i < inputPortReflectionInfos.Count; i++)
            {
                InputPortReflectionInfo inputPortReflectionInfo = inputPortReflectionInfos[i];
                InputPortEditorView     inputPortView           = new InputPortEditorView(this, inputPortReflectionInfo);
                inputPortView.portId = i;

                inputPortViewList.Add(inputPortView);
                allPortList.Add(inputPortView);
            }

            List <OutputPortReflectionInfo> outputPortReflectionInfos = reflectionInfo.outputPortInfoList;

            for (int i = 0; i < outputPortReflectionInfos.Count; i++)
            {
                OutputPortReflectionInfo outputPortReflectionInfo = outputPortReflectionInfos[i];
                OutputPortEditorView     outputPortView           = new OutputPortEditorView(this, outputPortReflectionInfo, i);
                outputPortView.portId = i;

                outputPortViewList.Add(outputPortView);
                allPortList.Add(outputPortView);
            }

            CalculateNodeSize();
        }
Esempio n. 10
0
        public void DrawNodeGUI()
        {
            if (graph == null)
            {
                return;
            }

            PositionInWindow = graph.GraphPositionToWindowPosition(PositionInGraph);
            viewRect.center  = PositionInWindow;

            if (isSelected)
            {
                Rect highLightRect = new Rect(viewRect);
                highLightRect.position = highLightRect.position - Vector2.one * 2f;
                highLightRect.max      = highLightRect.max + Vector2.one * 4f;
                GUI.Box(highLightRect, "", Utility.GetGuiStyle("Highlight"));
            }

            //draw back ground
            if (ReflectionInfo.IsEntranceNode)
            {
                GUI.Box(viewRect, "", Utility.GetGuiStyle("EntranceNode"));
            }

            if (ReflectionInfo.Type.IsSubclassOf(typeof(GraphVariableNodeBase)))
            {
                GUI.Box(viewRect, "", Utility.GetGuiStyle("NodeCyan"));
            }
            else
            {
                GUI.Box(viewRect, "", Utility.GetGuiStyle("NodeBg"));
            }

            //draw node name
            GUI.Label(NodeNameRect, string.Format("({0}){1}", NodeId, ReflectionInfo.NodeName), Utility.GetGuiStyle("NodeName"));

            leftPortLayoutHelper.SetPosition(new Vector2(viewRect.x, viewRect.y + NodeNameRect.height + PortAreaPadding));
            rightPortLayoutHelper.SetPosition(new Vector2(viewRect.x, viewRect.y + NodeNameRect.height + PortAreaPadding));

            if (flowInPortView != null)
            {
                flowInPortView.portViewRect = leftPortLayoutHelper.GetRect();
            }

            for (int i = 0; i < inputPortViewList.Count; i++)
            {
                InputPortEditorView inputPortView = inputPortViewList[i];
                inputPortView.portViewRect = leftPortLayoutHelper.GetRect();
            }

            if (flowOutPortViews.Length > 0)
            {
                for (int i = 0; i < flowOutPortViews.Length; i++)
                {
                    FlowOutPortEditorView flowoutPortView = flowOutPortViews[i];
                    flowoutPortView.portViewRect = rightPortLayoutHelper.GetRect();
                }
            }

            for (int i = 0; i < outputPortViewList.Count; i++)
            {
                OutputPortEditorView outputPortView = outputPortViewList[i];
                outputPortView.portViewRect = rightPortLayoutHelper.GetRect();
            }

            for (int i = 0; i < allPortList.Count; i++)
            {
                PortEditorView portView = allPortList[i];

                portView.Draw();
            }
        }