|
|
|
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
namespace UnityEditor.MaterialGraph |
|
|
|
|
|
|
ListPool<SerializableSlot>.Release(validSlots); |
|
|
|
} |
|
|
|
|
|
|
|
public static void CollectChildNodesByExecutionOrder(List<SerializableNode> nodeList, SerializableNode node, SerializableSlot slotToUse) |
|
|
|
// CollectNodesNodeFeedsInto looks at the current node and calculates
|
|
|
|
// which child nodes it depends on for it's calculation.
|
|
|
|
// Results are returned depth first so by processing each node in
|
|
|
|
// order you can generate a valid code block.
|
|
|
|
public static void DepthFirstCollectNodesFromNode(List<SerializableNode> nodeList, SerializableNode node, SerializableSlot slotToUse = null, bool includeSelf = true) |
|
|
|
// no where to start
|
|
|
|
// allready added this node
|
|
|
|
|
|
|
|
var validSlots = ListPool<SerializableSlot>.Get(); |
|
|
|
validSlots.AddRange(node.inputSlots); |
|
|
|
if (slotToUse != null && !validSlots.Contains(slotToUse)) |
|
|
|
{ |
|
|
|
ListPool<SerializableSlot>.Release(validSlots); |
|
|
|
|
|
|
|
// if we have a slot passed in but can not find it on the node abort
|
|
|
|
if (slotToUse != null && node.inputSlots.All(x => x.name != slotToUse.name)) |
|
|
|
} |
|
|
|
var validSlots = ListPool<SerializableSlot>.Get(); |
|
|
|
{ |
|
|
|
validSlots.Clear(); |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
validSlots.AddRange(node.inputSlots); |
|
|
|
|
|
|
|
|
|
|
|
var edges = node.owner.GetEdges(node.GetSlotReference(slot.name)); |
|
|
|
foreach (var edge in edges) |
|
|
|
|
|
|
|
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot.name))) |
|
|
|
CollectChildNodesByExecutionOrder(nodeList, outputNode, null); |
|
|
|
DepthFirstCollectNodesFromNode(nodeList, outputNode); |
|
|
|
nodeList.Add(node); |
|
|
|
if (includeSelf) |
|
|
|
nodeList.Add(node); |
|
|
|
public static void CollectDependentNodes(List<SerializableNode> nodeList, SerializableNode node) |
|
|
|
public static void CollectNodesNodeFeedsInto(List<SerializableNode> nodeList, SerializableNode node, bool includeSelf = true) |
|
|
|
{ |
|
|
|
if (node == null) |
|
|
|
return; |
|
|
|
|
|
|
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot.name))) |
|
|
|
{ |
|
|
|
var inputNode = node.owner.GetNodeFromGuid(edge.inputSlot.nodeGuid); |
|
|
|
CollectDependentNodes(nodeList, inputNode); |
|
|
|
CollectNodesNodeFeedsInto(nodeList, inputNode); |
|
|
|
nodeList.Add(node); |
|
|
|
if (includeSelf) |
|
|
|
nodeList.Add(node); |
|
|
|
} |
|
|
|
} |
|
|
|
} |