public void Initialize(NodeData nodeData, Object nodeDataContainer)
        {
            OnNewDataSelected(nodeData, nodeDataContainer);

            _newNodeMenu    = new GenericMenu();
            _rightClickMenu = new GenericMenu();

            foreach (var pair in NodeCollector.Nodes)
            {
                var info = pair.Value;
                if (string.IsNullOrEmpty(info.Path))
                {
                    continue;
                }
                _newNodeMenu.AddItem(new GUIContent(info.Path), false, data =>
                {
                    CreateNode((string)data, _graphViewSize * 0.5f - _scrollMain);
                }, info.TypeID);

                _rightClickMenu.AddItem(new GUIContent("Create/" + info.Path), false, data =>
                {
                    CreateNode((string)data, _rightClickMenuPosition - _scrollMain);
                }, info.TypeID);
            }
            Show();
            DefaultNode.InitDefaults(nodeData);
        }
        public Node CreateNode(string typeID, Vector2 pos)
        {
            Undo.RecordObject(_nodeDataContainer, "Create Node");
            Node node = _nodeData.CreateNode(typeID);

            node.Position = pos;
            DefaultNode.InitDefaults(node, _nodeData);
            RebuildGraph();
            return(node);
        }
示例#3
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();
                        }
                    }
                }
            }
示例#4
0
        void DrawProperty(Rect rect, Node node, string property, string name)
        {
            FieldInfo field = node.GetType().GetField(property);

            if (field == null)
            {
                return;
            }
            object value = field.GetValue(node);

            EditorGUI.BeginChangeCheck();
            value = DrawProperty(rect, field.FieldType, name, value);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(_nodeDataContainer, "Change Property");
                field.SetValue(node, value);

                node.UpdateTypes(_nodeData, new HashSet <Node>());
                DefaultNode.InitDefaults(node, _nodeData);

                RebuildGraph();
            }
        }