暫無描述
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.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. namespace Unity.VisualScripting
  2. {
  3. [UnitOrder(501)]
  4. public abstract class Lerp<T> : Unit
  5. {
  6. /// <summary>
  7. /// The first value.
  8. /// </summary>
  9. [DoNotSerialize]
  10. public ValueInput a { get; private set; }
  11. /// <summary>
  12. /// The second value.
  13. /// </summary>
  14. [DoNotSerialize]
  15. public ValueInput b { get; private set; }
  16. /// <summary>
  17. /// The interpolation value.
  18. /// </summary>
  19. [DoNotSerialize]
  20. public ValueInput t { get; private set; }
  21. /// <summary>
  22. /// The linear interpolation between A and B at T.
  23. /// </summary>
  24. [DoNotSerialize]
  25. [PortLabelHidden]
  26. public ValueOutput interpolation { get; private set; }
  27. [DoNotSerialize]
  28. protected virtual T defaultA => default(T);
  29. [DoNotSerialize]
  30. protected virtual T defaultB => default(T);
  31. protected override void Definition()
  32. {
  33. a = ValueInput(nameof(a), defaultA);
  34. b = ValueInput(nameof(b), defaultB);
  35. t = ValueInput<float>(nameof(t), 0);
  36. interpolation = ValueOutput(nameof(interpolation), Operation).Predictable();
  37. Requirement(a, interpolation);
  38. Requirement(b, interpolation);
  39. Requirement(t, interpolation);
  40. }
  41. private T Operation(Flow flow)
  42. {
  43. return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b), flow.GetValue<float>(t));
  44. }
  45. public abstract T Operation(T a, T b, float t);
  46. }
  47. }