IfNode.cs 944 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using GraphProcessor;
  5. using System.Linq;
  6. using NodeGraphProcessor.Examples;
  7. using UnityEngine.Rendering;
  8. [System.Serializable, NodeMenuItem("Conditional/If"), NodeMenuItem("Conditional/Branch")]
  9. public class IfNode : ConditionalNode
  10. {
  11. [Input(name = "Condition")]
  12. public bool condition;
  13. [Output(name = "True")]
  14. public ConditionalLink @true;
  15. [Output(name = "False")]
  16. public ConditionalLink @false;
  17. [Setting("Compare Function")]
  18. public CompareFunction compareOperator;
  19. public override string name => "If";
  20. public override IEnumerable< ConditionalNode > GetExecutedNodes()
  21. {
  22. string fieldName = condition ? nameof(@true) : nameof(@false);
  23. // Return all the nodes connected to either the true or false node
  24. return outputPorts.FirstOrDefault(n => n.fieldName == fieldName)
  25. .GetEdges().Select(e => e.inputNode as ConditionalNode);
  26. }
  27. }