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.

If.cs 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. namespace Unity.VisualScripting
  2. {
  3. /// <summary>
  4. /// Branches flow by checking if a condition is true or false.
  5. /// </summary>
  6. [UnitCategory("Control")]
  7. [UnitOrder(0)]
  8. [RenamedFrom("Bolt.Branch")]
  9. [RenamedFrom("Unity.VisualScripting.Branch")]
  10. public sealed class If : Unit, IBranchUnit
  11. {
  12. /// <summary>
  13. /// The entry point for the branch.
  14. /// </summary>
  15. [DoNotSerialize]
  16. [PortLabelHidden]
  17. public ControlInput enter { get; private set; }
  18. /// <summary>
  19. /// The condition to check.
  20. /// </summary>
  21. [DoNotSerialize]
  22. [PortLabelHidden]
  23. public ValueInput condition { get; private set; }
  24. /// <summary>
  25. /// The action to execute if the condition is true.
  26. /// </summary>
  27. [DoNotSerialize]
  28. [PortLabel("True")]
  29. public ControlOutput ifTrue { get; private set; }
  30. /// <summary>
  31. /// The action to execute if the condition is false.
  32. /// </summary>
  33. [DoNotSerialize]
  34. [PortLabel("False")]
  35. public ControlOutput ifFalse { get; private set; }
  36. protected override void Definition()
  37. {
  38. enter = ControlInput(nameof(enter), Enter);
  39. condition = ValueInput<bool>(nameof(condition));
  40. ifTrue = ControlOutput(nameof(ifTrue));
  41. ifFalse = ControlOutput(nameof(ifFalse));
  42. Requirement(condition, enter);
  43. Succession(enter, ifTrue);
  44. Succession(enter, ifFalse);
  45. }
  46. public ControlOutput Enter(Flow flow)
  47. {
  48. return flow.GetValue<bool>(condition) ? ifTrue : ifFalse;
  49. }
  50. }
  51. }