Exemple #1
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));
        }
Exemple #2
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);
        }
Exemple #3
0
        public InputPortEditorView(NodeEditorView nodeView, InputPortReflectionInfo inputPortReflectionInfo) : base(nodeView)
        {
            FlowType = FlowType.In;
            this.inputPortReflectionInfo = inputPortReflectionInfo;

            labelStyle     = Utility.GetGuiStyle("InputLabel");
            labelTextStyle = Utility.GetGuiStyle("InputLabelText");
        }
Exemple #4
0
        void InitInputPortReflectionInfos()
        {
            FieldInfo[] fieldInfos = Type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
            for (int i = 0; i < fieldInfos.Length; i++)
            {
                FieldInfo fieldInfo = fieldInfos[i];

                object[] attributeObjects = fieldInfo.GetCustomAttributes(typeof(NodeInputPortAttribute), false);
                if (attributeObjects.Length > 0)
                {
                    InputPortReflectionInfo inputPortReflectionInfo =
                        new InputPortReflectionInfo(attributeObjects[0] as NodeInputPortAttribute, fieldInfo, instance);
                    inputPortInfoList.Add(inputPortReflectionInfo);
                }
            }

            inputPortInfoList.Sort((a, b) => a.inputPortAttribute.priority - b.inputPortAttribute.priority);
        }
Exemple #5
0
        /// <summary>
        /// 根据input port的类型,将对应数据初始化
        /// </summary>
        /// <param name="inputPortReflectionInfo"></param>
        /// <param name="type"></param>
        /// <param name="valueString"></param>
        /// <param name="nodeView"></param>
        private static void SetNodeInputVariableValue(InputPortReflectionInfo inputPortReflectionInfo, Type type, string valueString,
                                                      NodeEditorView nodeView)
        {
            if (inputPortReflectionInfo.inputValueType != type)
            {
                Debug.LogErrorFormat("节点{0}中的Input Port {1} 的泛型改变了,之前是{2},现在是{3}", nodeView.ReflectionInfo.Type,
                                     inputPortReflectionInfo.PortName, type.FullName, inputPortReflectionInfo.inputValueType.FullName);
                return;
            }

            if (type == typeof(int))
            {
                int value = int.Parse(valueString);
                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type == typeof(float))
            {
                float value = float.Parse(valueString);
                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type == typeof(string))
            {
                inputPortReflectionInfo.SetInputNodeVariableValue(valueString);
            }
            else if (type == typeof(bool))
            {
                bool value = Boolean.Parse(valueString);
                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type.IsEnum)
            {
                object value = Enum.Parse(type, valueString);
                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type == typeof(List <int>))
            {
                string[]   splitString = valueString.Split('|');
                List <int> value       = new List <int>();
                for (int i = 0; i < splitString.Length; i++)
                {
                    value.Add(int.Parse(splitString[i]));
                }

                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type == typeof(LayerMaskWrapper))
            {
                LayerMaskWrapper value = valueString;
                inputPortReflectionInfo.SetInputNodeVariableValue(value);
            }
            else if (type == typeof(VariableWrapper))
            {
                int intValue;
                if (int.TryParse(valueString, out intValue))
                {
                    VariableWrapper variableWrapper = intValue;
                    inputPortReflectionInfo.SetInputNodeVariableValue(variableWrapper);
                }
                else
                {
                    Debug.LogErrorFormat("标记为VariableWrapper类型的input接口,但是它记录的值不是int类型的: {0}", valueString);
                }
            }
        }
Exemple #6
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();
        }