A game about forced loneliness, made by TACStudios
1using System; 2using UnityEngine; 3using UnityEditor.Graphing; 4using UnityEngine.Pool; 5 6namespace UnityEditor.ShaderGraph 7{ 8 sealed partial class GraphData : ISerializationCallbackReceiver 9 { 10 public static class GraphDataUtils 11 { 12 public static void ApplyActionLeafFirst(GraphData graph, Action<AbstractMaterialNode> action) 13 { 14 var temporaryMarks = PooledHashSet<string>.Get(); 15 var permanentMarks = PooledHashSet<string>.Get(); 16 var slots = ListPool<MaterialSlot>.Get(); 17 18 // Make sure we process a node's children before the node itself. 19 var stack = StackPool<AbstractMaterialNode>.Get(); 20 foreach (var node in graph.GetNodes<AbstractMaterialNode>()) 21 { 22 stack.Push(node); 23 } 24 while (stack.Count > 0) 25 { 26 var node = stack.Pop(); 27 if (permanentMarks.Contains(node.objectId)) 28 { 29 continue; 30 } 31 32 if (temporaryMarks.Contains(node.objectId)) 33 { 34 action.Invoke(node); 35 permanentMarks.Add(node.objectId); 36 } 37 else 38 { 39 temporaryMarks.Add(node.objectId); 40 stack.Push(node); 41 node.GetInputSlots(slots); 42 foreach (var inputSlot in slots) 43 { 44 var nodeEdges = graph.GetEdges(inputSlot.slotReference); 45 foreach (var edge in nodeEdges) 46 { 47 var fromSocketRef = edge.outputSlot; 48 var childNode = fromSocketRef.node; 49 if (childNode != null) 50 { 51 stack.Push(childNode); 52 } 53 } 54 } 55 slots.Clear(); 56 } 57 } 58 59 StackPool<AbstractMaterialNode>.Release(stack); 60 ListPool<MaterialSlot>.Release(slots); 61 temporaryMarks.Dispose(); 62 permanentMarks.Dispose(); 63 } 64 } 65 } 66}