CompatibilityExtensions.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.ShaderGraph.Drawing
  5. {
  6. static class CompatibilityExtensions
  7. {
  8. #if !UNITY_2018_3_OR_NEWER
  9. public static void MarkDirtyRepaint(this VisualElement element)
  10. {
  11. element.Dirty(ChangeType.Repaint);
  12. }
  13. #endif
  14. #if !UNITY_2018_3_OR_NEWER
  15. public static void CaptureMouse(this VisualElement element)
  16. {
  17. element.TakeMouseCapture();
  18. }
  19. public static void ReleaseMouse(this VisualElement element)
  20. {
  21. element.ReleaseMouseCapture();
  22. }
  23. #endif
  24. public static void OnToggleChanged(this Toggle toggle, EventCallback<ChangeEvent<bool>> callback)
  25. {
  26. #if UNITY_2018_3_OR_NEWER
  27. toggle.RegisterValueChangedCallback(callback);
  28. #else
  29. toggle.OnToggle(() => callback(ChangeEvent<bool>.GetPooled(!toggle.value, toggle.value)));
  30. #endif
  31. }
  32. }
  33. static class TrickleDownEnum
  34. {
  35. #if UNITY_2018_3_OR_NEWER
  36. public static readonly TrickleDown NoTrickleDown = TrickleDown.NoTrickleDown;
  37. public static readonly TrickleDown TrickleDown = TrickleDown.TrickleDown;
  38. #else
  39. public static readonly Capture NoTrickleDown = Capture.NoCapture;
  40. public static readonly Capture TrickleDown = Capture.Capture;
  41. #endif
  42. }
  43. }