Пример #1
0
        public static string Serialize(Dictionary <int, Node> nodes)
        {
            HashSet <int> usedDefaults = GetUsedDefaults(nodes);
            StringBuilder sb           = new StringBuilder();
            bool          first        = true;

            foreach (var pair in nodes)
            {
                Node node = pair.Value;
                if (node is DefaultNode && !usedDefaults.Contains(node.NodeId))
                {
                    continue;
                }
                if (!first)
                {
                    sb.Append('#');
                }
                first = false;
                sb.Append(NodeCollector.ToID(node.GetType()));
                sb.Append('|');
                sb.Append(node.NodeId);
                sb.Append('|');
                ICustomSerialiser custom = node as ICustomSerialiser;
                if (custom != null)
                {
                    sb.Append(custom.Serialize());
                    continue;
                }
                sb.Append(PositionToString(node.Position));
                sb.Append('|');
                for (int i = 0; i < node.Inputs.Length; i++)
                {
                    if (i != 0)
                    {
                        sb.Append(' ');
                    }
                    sb.Append(node.Inputs[i].NodeId);
                }
                sb.Append('|');

                FieldInfo[] fields = node.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
                for (int i = 0; i < fields.Length; i++)
                {
                    if ((fields[i].Attributes & FieldAttributes.NotSerialized) != 0)
                    {
                        continue;
                    }
                    if (Exeptions.Contains(fields[i].Name))
                    {
                        continue;
                    }
                    if (i != 0)
                    {
                        sb.Append('|');
                    }
                    sb.Append(SerializeField(fields[i], node));
                }
            }
            return(sb.ToString());
        }
Пример #2
0
            public void ProcessNodeInput(Node node, int inputId, Rect bigRect, Rect smallRect)
            {
                Event     currentEvent = Event.current;
                EventType eventType    = currentEvent.type;

                if (_node != null)//draging
                {
                    if (!bigRect.Contains(currentEvent.mousePosition))
                    {
                        return;
                    }
                    Link link = node.Inputs[inputId];


                    bool validate = NodeCollector.ValidateTypes(link.Type, _node.CashedOutputType) || NodeCollector.ValidateTypes(_node.CashedOutputType, link.Type);
                    if (eventType == EventType.Repaint && validate)
                    {
                        _hoverInput    = true;
                        _inputPosition = GetNodeInputPosition(node, inputId);
                    }

                    if (eventType == EventType.MouseUp && currentEvent.button == 0)
                    {
                        Undo.RecordObject(Window._nodeDataContainer, "Change Link");
                        if (validate)
                        {
                            link.NodeId = _node.NodeId;
                        }
                    }
                }
                else//
                {
                    if (eventType == EventType.MouseDown && currentEvent.button == 0 && smallRect.Contains(currentEvent.mousePosition))
                    {
                        Link link   = node.Inputs[inputId];
                        Node inNode = Window._nodeData.GetNode(link);
                        if (inNode != null)
                        {
                            Undo.RecordObject(Window._nodeDataContainer, "Change Link");
                            _node       = inNode;
                            link.NodeId = Node.NoNodeID;

                            DefaultNode.ToDefault(link, Window._nodeData);

                            _hoverInput = false;
                            Window.RebuildGraph();
                            currentEvent.Use();
                        }
                    }
                }
            }
Пример #3
0
        ValueType GetMember()
        {
            bool      found = _reflectedValue.FindMember(Component ? Component : null, Address);
            ValueType valueType;

            if (found && _reflectedValue.ValidateGet())
            {
                valueType = NodeCollector.GetValueType(_reflectedValue.Type);
            }
            else
            {
                valueType = ValueType.Error;
            }
            return(valueType);
        }
Пример #4
0
        public static void ToDefault(Link link, NodeData nodeData)
        {
            if (link.NoDefaults)
            {
                return;
            }
            if (link.NodeId > NoNodeID)
            {
                return;
            }

            int nodeID = link.NodeId < NoNodeID ? link.NodeId : link.LastDefaultNode;

            Node defaultNode = nodeID < NoNodeID?nodeData.GetNode(link.NodeId) : null;

            if (defaultNode == null || !NodeCollector.ValidateTypes(link.Type, defaultNode.OutputType))
            {
                defaultNode = nodeData.CreateDefaultNode(link.Type);
            }

            link.LastDefaultNode = link.NodeId = defaultNode != null ? defaultNode.NodeId : NoNodeID;
        }
Пример #5
0
        public Node CreateNode(Node node)
        {
            string typeID = NodeCollector.ToID(node.GetType());

            return(CreateNode(typeID));
        }