GUIVector2DistributionField.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. partial class GUIVector2DistributionField
  6. {
  7. /// <summary>
  8. /// Triggered when the distribution in the field changes.
  9. /// </summary>
  10. public event Action OnChanged;
  11. /// <summary>
  12. /// Triggered whenever user confirms input in one of the floating point fields.
  13. /// </summary>
  14. public event Action OnConfirmed;
  15. partial void OnClicked(int component)
  16. {
  17. Vector2Distribution distribution = Value;
  18. if (DistributionType == PropertyDistributionType.Curve)
  19. {
  20. AnimationCurve[] curves = AnimationUtility.SplitCurve2D(distribution.GetMinCurve());
  21. if (component < curves.Length)
  22. {
  23. CurveEditorWindow.Show(curves[component], (success, curve) =>
  24. {
  25. if (!success)
  26. return;
  27. curves[component] = curve;
  28. Vector2Curve compoundCurve = AnimationUtility.CombineCurve2D(curves);
  29. Value = new Vector2Distribution(compoundCurve);
  30. OnChanged?.Invoke();
  31. });
  32. }
  33. }
  34. else if (DistributionType == PropertyDistributionType.RandomCurveRange)
  35. {
  36. AnimationCurve[] minCurves = AnimationUtility.SplitCurve2D(distribution.GetMinCurve());
  37. AnimationCurve[] maxCurves = AnimationUtility.SplitCurve2D(distribution.GetMaxCurve());
  38. if (component < minCurves.Length && component < maxCurves.Length)
  39. {
  40. CurveEditorWindow.Show(minCurves[component], maxCurves[component],
  41. (success, minCurve, maxCurve) =>
  42. {
  43. if (!success)
  44. return;
  45. minCurves[component] = minCurve;
  46. maxCurves[component] = maxCurve;
  47. Vector2Curve minCompoundCurves = AnimationUtility.CombineCurve2D(minCurves);
  48. Vector2Curve maxCompoundCurves = AnimationUtility.CombineCurve2D(maxCurves);
  49. Value = new Vector2Distribution(minCompoundCurves, maxCompoundCurves);
  50. OnChanged?.Invoke();
  51. });
  52. }
  53. }
  54. }
  55. partial void OnConstantModified()
  56. {
  57. OnChanged?.Invoke();
  58. }
  59. partial void OnConstantConfirmed()
  60. {
  61. OnConfirmed?.Invoke();
  62. }
  63. }
  64. }