GUIVector2DistributionField.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. OnConfirmed?.Invoke();
  32. });
  33. }
  34. }
  35. else if (DistributionType == PropertyDistributionType.RandomCurveRange)
  36. {
  37. AnimationCurve[] minCurves = AnimationUtility.SplitCurve2D(distribution.GetMinCurve());
  38. AnimationCurve[] maxCurves = AnimationUtility.SplitCurve2D(distribution.GetMaxCurve());
  39. if (component < minCurves.Length && component < maxCurves.Length)
  40. {
  41. CurveEditorWindow.Show(minCurves[component], maxCurves[component],
  42. (success, minCurve, maxCurve) =>
  43. {
  44. if (!success)
  45. return;
  46. minCurves[component] = minCurve;
  47. maxCurves[component] = maxCurve;
  48. Vector2Curve minCompoundCurves = AnimationUtility.CombineCurve2D(minCurves);
  49. Vector2Curve maxCompoundCurves = AnimationUtility.CombineCurve2D(maxCurves);
  50. Value = new Vector2Distribution(minCompoundCurves, maxCompoundCurves);
  51. OnChanged?.Invoke();
  52. OnConfirmed?.Invoke();
  53. });
  54. }
  55. }
  56. }
  57. partial void OnConstantModified()
  58. {
  59. OnChanged?.Invoke();
  60. }
  61. partial void OnConstantConfirmed()
  62. {
  63. OnConfirmed?.Invoke();
  64. }
  65. }
  66. }