VFXFlipBookField.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using UnityEngine;
  2. using UnityEngine.UIElements;
  3. using UnityEditor.UIElements;
  4. using System.Collections.Generic;
  5. namespace UnityEditor.VFX.UI
  6. {
  7. class VFXFlipBookField : VFXControl<FlipBook>
  8. {
  9. VFXLabeledField<IntegerField, int> m_X;
  10. VFXLabeledField<IntegerField, int> m_Y;
  11. void CreateTextField()
  12. {
  13. m_X = new VFXLabeledField<IntegerField, int>("X");
  14. m_Y = new VFXLabeledField<IntegerField, int>("Y");
  15. m_X.control.AddToClassList("fieldContainer");
  16. m_Y.control.AddToClassList("fieldContainer");
  17. m_X.AddToClassList("fieldContainer");
  18. m_Y.AddToClassList("fieldContainer");
  19. m_X.RegisterCallback<ChangeEvent<int>>(OnXValueChanged);
  20. m_Y.RegisterCallback<ChangeEvent<int>>(OnYValueChanged);
  21. }
  22. void OnXValueChanged(ChangeEvent<int> e)
  23. {
  24. FlipBook newValue = value;
  25. newValue.x = (int)m_X.value;
  26. SetValueAndNotify(newValue);
  27. }
  28. void OnYValueChanged(ChangeEvent<int> e)
  29. {
  30. FlipBook newValue = value;
  31. newValue.y = (int)m_Y.value;
  32. SetValueAndNotify(newValue);
  33. }
  34. public override bool indeterminate
  35. {
  36. get
  37. {
  38. return m_X.indeterminate;
  39. }
  40. set
  41. {
  42. m_X.indeterminate = value;
  43. m_Y.indeterminate = value;
  44. }
  45. }
  46. public VFXFlipBookField()
  47. {
  48. CreateTextField();
  49. style.flexDirection = FlexDirection.Row;
  50. Add(m_X);
  51. Add(m_Y);
  52. }
  53. protected override void ValueToGUI(bool force)
  54. {
  55. if (!m_X.control.HasFocus() || force)
  56. m_X.value = value.x;
  57. if (!m_Y.control.HasFocus() || force)
  58. m_Y.value = value.y;
  59. }
  60. }
  61. }