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

BinaryComparisonUnit.cs 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. namespace Unity.VisualScripting
  2. {
  3. [UnitCategory("Logic")]
  4. public abstract class BinaryComparisonUnit : Unit
  5. {
  6. /// <summary>
  7. /// The first input.
  8. /// </summary>
  9. [DoNotSerialize]
  10. public ValueInput a { get; private set; }
  11. /// <summary>
  12. /// The second input.
  13. /// </summary>
  14. [DoNotSerialize]
  15. public ValueInput b { get; private set; }
  16. [DoNotSerialize]
  17. public virtual ValueOutput comparison { get; private set; }
  18. /// <summary>
  19. /// Whether the compared inputs are numbers.
  20. /// </summary>
  21. [Serialize]
  22. [Inspectable]
  23. [InspectorToggleLeft]
  24. public bool numeric { get; set; } = true;
  25. // Backwards compatibility
  26. protected virtual string outputKey => nameof(comparison);
  27. protected override void Definition()
  28. {
  29. if (numeric)
  30. {
  31. a = ValueInput<float>(nameof(a));
  32. b = ValueInput<float>(nameof(b), 0);
  33. comparison = ValueOutput(outputKey, NumericComparison).Predictable();
  34. }
  35. else
  36. {
  37. a = ValueInput<object>(nameof(a)).AllowsNull();
  38. b = ValueInput<object>(nameof(b)).AllowsNull();
  39. comparison = ValueOutput(outputKey, GenericComparison).Predictable();
  40. }
  41. Requirement(a, comparison);
  42. Requirement(b, comparison);
  43. }
  44. private bool NumericComparison(Flow flow)
  45. {
  46. return NumericComparison(flow.GetValue<float>(a), flow.GetValue<float>(b));
  47. }
  48. private bool GenericComparison(Flow flow)
  49. {
  50. return GenericComparison(flow.GetValue(a), flow.GetValue(b));
  51. }
  52. protected abstract bool NumericComparison(float a, float b);
  53. protected abstract bool GenericComparison(object a, object b);
  54. }
  55. }