|
|
|
|
|
|
List<IEdge> m_Edges = new List<IEdge>(); |
|
|
|
|
|
|
|
[NonSerialized] |
|
|
|
Dictionary<Guid, List<IEdge>> m_NodeEdges = new Dictionary<Guid, List<IEdge>>(); |
|
|
|
|
|
|
|
[NonSerialized] |
|
|
|
Dictionary<Guid, INode> m_Nodes = new Dictionary<Guid, INode>(); |
|
|
|
|
|
|
|
[SerializeField] |
|
|
|
|
|
|
m_Nodes.Remove(node.guid); |
|
|
|
} |
|
|
|
|
|
|
|
void AddEdgeToNodeEdges(IEdge edge) |
|
|
|
{ |
|
|
|
List<IEdge> inputEdges; |
|
|
|
if (!m_NodeEdges.TryGetValue(edge.inputSlot.nodeGuid, out inputEdges)) |
|
|
|
m_NodeEdges[edge.inputSlot.nodeGuid] = inputEdges = new List<IEdge>(); |
|
|
|
inputEdges.Add(edge); |
|
|
|
|
|
|
|
List<IEdge> outputEdges; |
|
|
|
if (!m_NodeEdges.TryGetValue(edge.outputSlot.nodeGuid, out outputEdges)) |
|
|
|
m_NodeEdges[edge.outputSlot.nodeGuid] = outputEdges = new List<IEdge>(); |
|
|
|
outputEdges.Add(edge); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo> GetLegacyTypeRemapping() |
|
|
|
{ |
|
|
|
return new Dictionary<SerializationHelper.TypeSerializationInfo, SerializationHelper.TypeSerializationInfo>(); |
|
|
|
|
|
|
|
|
|
|
var newEdge = new Edge(outputSlot, inputSlot); |
|
|
|
m_Edges.Add(newEdge); |
|
|
|
AddEdgeToNodeEdges(newEdge); |
|
|
|
|
|
|
|
Debug.Log("Connected edge: " + newEdge); |
|
|
|
ValidateGraph(); |
|
|
|
|
|
|
public virtual void RemoveEdge(IEdge e) |
|
|
|
{ |
|
|
|
m_Edges.Remove(e); |
|
|
|
RemoveEdgeNoValidate(e); |
|
|
|
ValidateGraph(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
void RemoveEdgeNoValidate(IEdge e) |
|
|
|
{ |
|
|
|
m_Edges.Remove(e); |
|
|
|
|
|
|
|
List<IEdge> inputNodeEdges; |
|
|
|
if (m_NodeEdges.TryGetValue(e.inputSlot.nodeGuid, out inputNodeEdges)) |
|
|
|
inputNodeEdges.Remove(e); |
|
|
|
|
|
|
|
List<IEdge> outputNodeEdges; |
|
|
|
if (m_NodeEdges.TryGetValue(e.outputSlot.nodeGuid, out outputNodeEdges)) |
|
|
|
outputNodeEdges.Remove(e); |
|
|
|
} |
|
|
|
|
|
|
|
public INode GetNodeFromGuid(Guid guid) |
|
|
|
|
|
|
public IEnumerable<IEdge> GetEdges(SlotReference s) |
|
|
|
{ |
|
|
|
if (s == null) |
|
|
|
return new Edge[0]; |
|
|
|
return Enumerable.Empty<IEdge>(); |
|
|
|
|
|
|
|
List<IEdge> candidateEdges; |
|
|
|
if (!m_NodeEdges.TryGetValue(s.nodeGuid, out candidateEdges)) |
|
|
|
return Enumerable.Empty<IEdge>(); |
|
|
|
return m_Edges.Where(x => |
|
|
|
return candidateEdges.Where(x => |
|
|
|
|| x.inputSlot.nodeGuid == s.nodeGuid && x.inputSlot.slotId == s.slotId).ToList(); |
|
|
|
|| x.inputSlot.nodeGuid == s.nodeGuid && x.inputSlot.slotId == s.slotId); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void OnBeforeSerialize() |
|
|
|
|
|
|
|
|
|
|
m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null); |
|
|
|
m_SerializableEdges = null; |
|
|
|
foreach (var edge in m_Edges) |
|
|
|
AddEdgeToNodeEdges(edge); |
|
|
|
|
|
|
|
ValidateGraph(); |
|
|
|
} |
|
|
|