No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GraphDataUtils.cs 2.4KB

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