Пример #1
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);
        }
Пример #2
0
 public void RemoveEdge(SerializedEdge serializedEdge)
 {
     _logicGraphEditorObject.LogicGraphData.SerializedEdges.Remove(serializedEdge);
     foreach (var edge in _graphView.edges.ToList())
     {
         if (edge.userData == serializedEdge)
         {
             Debug.Log("removing edge " + edge);
             _graphView.RemoveElement(edge);
         }
     }
 }
Пример #3
0
        public void AddEdge(LogicSlot leftLogicSlot, LogicSlot rightLogicSlot)
        {
            SerializedEdge serializedEdge = new SerializedEdge
            {
                SourceNodeGuid   = leftLogicSlot.Owner.NodeGuid,
                SourceMemberName = leftLogicSlot.MemberName,
                TargetNodeGuid   = rightLogicSlot.Owner.NodeGuid,
                TargetMemberName = rightLogicSlot.MemberName
            };

            _logicGraphEditorObject.LogicGraphData.SerializedEdges.Add(serializedEdge);

            AddEdge(serializedEdge);
        }
        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
        public void AddEdge(Edge edgeView)
        {
            LogicSlot leftLogicSlot;
            LogicSlot rightLogicSlot;

            GetSlots(edgeView, out leftLogicSlot, out rightLogicSlot);

            _logicGraphEditorObject.RegisterCompleteObjectUndo("Connect Edge");
            SerializedEdge serializedEdge = new SerializedEdge
            {
                SourceNodeGuid   = leftLogicSlot.Owner.NodeGuid,
                SourceMemberName = leftLogicSlot.MemberName,
                TargetNodeGuid   = rightLogicSlot.Owner.NodeGuid,
                TargetMemberName = rightLogicSlot.MemberName
            };

            _logicGraphEditorObject.LogicGraphData.SerializedEdges.Add(serializedEdge);

            edgeView.userData = serializedEdge;
            edgeView.output.Connect(edgeView);
            edgeView.input.Connect(edgeView);
            _graphView.AddElement(edgeView);
        }