コード例 #1
0
        public SerializedNode AddNode(AbstractLogicNodeEditor logicNodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + logicNodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = logicNodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(logicNodeEditor)
            };

            logicNodeEditor.SerializedNode = serializedNode;
            if (logicNodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (logicNodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            logicNodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = logicNodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
            nodeView.MarkDirtyRepaint();
            return(serializedNode);
        }
コード例 #2
0
        public void AddNode(NodeEditor nodeEditor)
        {
            _logicGraphEditorObject.RegisterCompleteObjectUndo("Add Node " + nodeEditor.NodeType());

            SerializedNode serializedNode = new SerializedNode
            {
                NodeType = nodeEditor.NodeType(),
                JSON     = JsonUtility.ToJson(nodeEditor)
            };

            nodeEditor.SerializedNode = serializedNode;
            if (nodeEditor is IInputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedInputNodes.Add(serializedNode);
            }
            else if (nodeEditor is IOutputNode)
            {
                _logicGraphEditorObject.LogicGraphData.SerializedOutputNodes.Add(serializedNode);
            }
            else
            {
                _logicGraphEditorObject.LogicGraphData.SerializedNodes.Add(serializedNode);
            }

            nodeEditor.Owner = _graphView;
            var nodeView = new LogicNodeView {
                userData = nodeEditor
            };

            _graphView.AddElement(nodeView);
            nodeView.Initialize(nodeEditor, _edgeConnectorListener);
            nodeView.Dirty(ChangeType.Repaint);
        }
コード例 #3
0
        public bool AddEdge(SerializedEdge serializedEdge)
        {
            LogicNodeView sourceNodeView = _graphView.nodes.ToList().OfType <LogicNodeView>()
                                           .FirstOrDefault(x => x.LogicNodeEditor.NodeGuid == serializedEdge.SourceNodeGuid);

            if (sourceNodeView == null)
            {
                Debug.LogWarning($"Source NodeGUID not found {serializedEdge.SourceNodeGuid}");
                return(false);
            }

            LogicPort sourceAnchor = sourceNodeView.outputContainer.Children().OfType <LogicPort>()
                                     .FirstOrDefault(x => x.Slot.MemberName == serializedEdge.SourceMemberName);

            if (sourceAnchor == null)
            {
                Debug.LogError($"Source anchor null {serializedEdge.SourceMemberName} {serializedEdge.SourceNodeGuid}");
                return(false);
            }

            LogicNodeView targetNodeView = _graphView.nodes.ToList().OfType <LogicNodeView>()
                                           .FirstOrDefault(x => x.LogicNodeEditor.NodeGuid == serializedEdge.TargetNodeGuid);

            if (targetNodeView == null)
            {
                Debug.LogWarning($"Target NodeGUID not found {serializedEdge.TargetNodeGuid}");
                return(false);
            }

            LogicPort targetAnchor = targetNodeView.inputContainer.Children().OfType <LogicPort>()
                                     .FirstOrDefault(x => x.Slot.MemberName == serializedEdge.TargetMemberName);

            if (targetAnchor == null)
            {
                Debug.LogError($"Target anchor null {serializedEdge.SourceMemberName} {serializedEdge.TargetNodeGuid}");
                return(false);
            }

            var edgeView = new Edge
            {
                userData = serializedEdge,
                output   = sourceAnchor,
                input    = targetAnchor
            };

            edgeView.output.Connect(edgeView);
            edgeView.input.Connect(edgeView);
            _graphView.AddElement(edgeView);
            targetNodeView.UpdatePortInputVisibilities();
            sourceNodeView.UpdatePortInputVisibilities();

            return(true);
        }
コード例 #4
0
        private void AddEdgeFromLoad(SerializedEdge serializedEdge)
        {
            LogicNodeView sourceNodeView = _graphView.nodes.ToList().OfType <LogicNodeView>()
                                           .FirstOrDefault(x => x.NodeEditor.NodeGuid == serializedEdge.SourceNodeGuid);

            if (sourceNodeView == null)
            {
                Debug.LogWarning($"Source NodeGUID not found {serializedEdge.SourceNodeGuid}");
                return;
            }

            PortView sourceAnchor = sourceNodeView.outputContainer.Children().OfType <PortView>()
                                    .FirstOrDefault(x => x.PortDescription.MemberName == serializedEdge.SourceMemberName);

            if (sourceAnchor == null)
            {
                Debug.LogError($"Source anchor null {serializedEdge.SourceMemberName}");
                return;
            }

            LogicNodeView targetNodeView = _graphView.nodes.ToList().OfType <LogicNodeView>()
                                           .FirstOrDefault(x => x.NodeEditor.NodeGuid == serializedEdge.TargetNodeGuid);

            if (targetNodeView == null)
            {
                Debug.LogWarning($"Target NodeGUID not found {serializedEdge.TargetNodeGuid}");
                return;
            }

            PortView targetAnchor = targetNodeView.inputContainer.Children().OfType <PortView>()
                                    .FirstOrDefault(x => x.PortDescription.MemberName == serializedEdge.TargetMemberName);

            var edgeView = new Edge
            {
                userData = serializedEdge,
                output   = sourceAnchor,
                input    = targetAnchor
            };

            edgeView.output.Connect(edgeView);
            edgeView.input.Connect(edgeView);
            _graphView.AddElement(edgeView);
        }
コード例 #5
0
        private void AddNode(SerializedNode serializedNode)
        {
            AbstractLogicNodeEditor logicNodeEditor = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var type in assembly.GetTypes())
                {
                    if (type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(AbstractLogicNodeEditor)))
                    {
                        var attrs = type.GetCustomAttributes(typeof(NodeEditorType), false) as NodeEditorType[];
                        if (attrs != null && attrs.Length > 0)
                        {
                            if (attrs[0].NodeType.Name == serializedNode.NodeType)
                            {
                                logicNodeEditor = (AbstractLogicNodeEditor)Activator.CreateInstance(type);
                            }
                        }
                    }
                }
            }

            if (logicNodeEditor != null)
            {
                JsonUtility.FromJsonOverwrite(serializedNode.JSON, logicNodeEditor);
                logicNodeEditor.SerializedNode = serializedNode;
                logicNodeEditor.Owner          = _graphView;
                var nodeView = new LogicNodeView {
                    userData = logicNodeEditor
                };
                _graphView.AddElement(nodeView);
                nodeView.Initialize(logicNodeEditor, _edgeConnectorListener);
                nodeView.MarkDirtyRepaint();
            }
            else
            {
                Debug.LogWarning("No NodeEditor found for " + serializedNode);
            }
        }