Beispiel #1
0
        void CalculateNodeSize()
        {
            float nodeNameWidth =
                Utility.GetStringGuiWidth(ReflectionInfo.NodeName + "(0)   ", Utility.GetGuiStyle("NodeName").fontSize);
            //width
            float leftMaxWidth = 0f, rightMaxWidth = 0f;
            int   leftPortCount  = 0;
            int   rightPortCount = 0;

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

                if (portView.FlowType == FlowType.In)
                {
                    leftPortCount++;
                    if (width > leftMaxWidth)
                    {
                        leftMaxWidth = width;
                    }
                }
                else
                {
                    rightPortCount++;
                    if (width > rightMaxWidth)
                    {
                        rightMaxWidth = width;
                    }
                }
            }

            viewRect.width  = Mathf.Max(leftMaxWidth + rightMaxWidth + PortAreaPadding, nodeNameWidth);
            viewRect.height = NodeNameRect.height + PortAreaPadding + Mathf.Max(
                PortLayoutHelper.CalculateHeightByPortCount(leftPortCount),
                PortLayoutHelper.CalculateHeightByPortCount(rightPortCount));


            leftPortLayoutHelper.SetOffset(0, leftMaxWidth);
            rightPortLayoutHelper.SetOffset(viewRect.width - rightMaxWidth, rightMaxWidth); //中间留点padding
        }
Beispiel #2
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();
        }