暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. namespace Unity.VisualScripting
  3. {
  4. /// <summary>
  5. /// Throws an exception.
  6. /// </summary>
  7. [UnitCategory("Control")]
  8. [UnitOrder(16)]
  9. public sealed class Throw : Unit
  10. {
  11. /// <summary>
  12. /// Whether a custom exception object should be specified manually.
  13. /// </summary>
  14. [Serialize]
  15. [Inspectable, UnitHeaderInspectable("Custom")]
  16. [InspectorToggleLeft]
  17. public bool custom { get; set; }
  18. /// <summary>
  19. /// The entry point to throw the exception.
  20. /// </summary>
  21. [DoNotSerialize]
  22. [PortLabelHidden]
  23. public ControlInput enter { get; private set; }
  24. /// <summary>
  25. /// The message of the exception.
  26. /// </summary>
  27. [DoNotSerialize]
  28. public ValueInput message { get; private set; }
  29. /// <summary>
  30. /// The exception to throw.
  31. /// </summary>
  32. [DoNotSerialize]
  33. public ValueInput exception { get; private set; }
  34. protected override void Definition()
  35. {
  36. if (custom)
  37. {
  38. enter = ControlInput(nameof(enter), ThrowCustom);
  39. exception = ValueInput<Exception>(nameof(exception));
  40. Requirement(exception, enter);
  41. }
  42. else
  43. {
  44. enter = ControlInput(nameof(enter), ThrowMessage);
  45. message = ValueInput(nameof(message), string.Empty);
  46. Requirement(message, enter);
  47. }
  48. }
  49. private ControlOutput ThrowCustom(Flow flow)
  50. {
  51. throw flow.GetValue<Exception>(exception);
  52. }
  53. private ControlOutput ThrowMessage(Flow flow)
  54. {
  55. throw new Exception(flow.GetValue<string>(message));
  56. }
  57. }
  58. }