GUIVector3DistributionField.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using bs;
  3. namespace bs.Editor
  4. {
  5. partial class GUIVector3DistributionField
  6. {
  7. /// <summary>
  8. /// Triggered when one of the curves in the distribution changes.
  9. /// </summary>
  10. public event Action OnCurveChanged;
  11. partial void Callback_OnClicked(VectorComponent component)
  12. {
  13. int componentIdx = (int) component;
  14. Vector3Distribution distribution = Value;
  15. if (DistributionType == PropertyDistributionType.Curve)
  16. {
  17. AnimationCurve[] curves = AnimationUtility.SplitCurve3D(distribution.GetMinCurve());
  18. if (componentIdx < curves.Length)
  19. {
  20. CurveEditorWindow.Show(curves[componentIdx], (success, curve) =>
  21. {
  22. if (!success)
  23. return;
  24. curves[componentIdx] = curve;
  25. Vector3Curve compoundCurve = AnimationUtility.CombineCurve3D(curves);
  26. Value = new Vector3Distribution(compoundCurve);
  27. OnCurveChanged?.Invoke();
  28. });
  29. }
  30. }
  31. else if (DistributionType == PropertyDistributionType.RandomCurveRange)
  32. {
  33. AnimationCurve[] minCurves = AnimationUtility.SplitCurve3D(distribution.GetMinCurve());
  34. AnimationCurve[] maxCurves = AnimationUtility.SplitCurve3D(distribution.GetMaxCurve());
  35. if (componentIdx < minCurves.Length && componentIdx < maxCurves.Length)
  36. {
  37. CurveEditorWindow.Show(minCurves[componentIdx], maxCurves[componentIdx],
  38. (success, minCurve, maxCurve) =>
  39. {
  40. if (!success)
  41. return;
  42. minCurves[componentIdx] = minCurve;
  43. maxCurves[componentIdx] = maxCurve;
  44. Vector3Curve minCompoundCurves = AnimationUtility.CombineCurve3D(minCurves);
  45. Vector3Curve maxCompoundCurves = AnimationUtility.CombineCurve3D(maxCurves);
  46. Value = new Vector3Distribution(minCompoundCurves, maxCompoundCurves);
  47. OnCurveChanged?.Invoke();
  48. });
  49. }
  50. }
  51. }
  52. }
  53. }