浏览代码

Add dictionary for storing `Node -> Edges` reference in SerializableGraph (faster/more scalable edge look-ups)

/main
Peter Bay Bastian 7 年前
当前提交
1e3fb5de
共有 1 个文件被更改,包括 35 次插入4 次删除
  1. 39
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs

39
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


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();
}

正在加载...
取消
保存