VFXExpressionSampleCurve.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Linq;
  3. using System.Runtime.CompilerServices;
  4. using UnityEngine;
  5. using UnityEngine.VFX;
  6. namespace UnityEditor.VFX
  7. {
  8. class VFXExpressionSampleCurve : VFXExpression
  9. {
  10. public VFXExpressionSampleCurve() : this(VFXValue<AnimationCurve>.Default, VFXValue<float>.Default)
  11. {
  12. }
  13. public VFXExpressionSampleCurve(VFXExpression curve, VFXExpression time)
  14. : base(Flags.None, new VFXExpression[2] { curve, time })
  15. { }
  16. sealed public override VFXExpressionOperation operation { get { return VFXExpressionOperation.SampleCurve; } }
  17. protected sealed override VFXExpression Evaluate(VFXExpression[] constParents)
  18. {
  19. var timeReduce = constParents[1];
  20. var curveReduce = constParents[0];
  21. var curve = curveReduce.Get<AnimationCurve>();
  22. var time = timeReduce.Get<float>();
  23. return VFXValue.Constant(curve.Evaluate(time));
  24. }
  25. public sealed override string GetCodeString(string[] parents)
  26. {
  27. return string.Format("SampleCurve({0},{1})", parents[0], parents[1]);
  28. }
  29. }
  30. }