VFXBlockUI.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System.Collections.Generic;
  2. using UnityEditor.Experimental.GraphView;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. using System.Reflection;
  6. using System.Linq;
  7. using UnityEngine.Profiling;
  8. using PositionType = UnityEngine.UIElements.Position;
  9. namespace UnityEditor.VFX.UI
  10. {
  11. class VFXBlockUI : VFXNodeUI
  12. {
  13. Toggle m_EnableToggle;
  14. public new VFXBlockController controller
  15. {
  16. get { return base.controller as VFXBlockController; }
  17. set { base.controller = value; }
  18. }
  19. protected override bool HasPosition()
  20. {
  21. return false;
  22. }
  23. public VFXContextUI context
  24. {
  25. get { return this.GetFirstAncestorOfType<VFXContextUI>(); }
  26. }
  27. public VFXBlockUI()
  28. {
  29. Profiler.BeginSample("VFXBlockUI.VFXBlockUI");
  30. this.AddStyleSheetPath("VFXBlock");
  31. pickingMode = PickingMode.Position;
  32. m_EnableToggle = new Toggle();
  33. m_EnableToggle.RegisterCallback<ChangeEvent<bool>>(OnToggleEnable);
  34. titleContainer.Insert(1, m_EnableToggle);
  35. capabilities &= ~Capabilities.Ascendable;
  36. capabilities |= Capabilities.Selectable | Capabilities.Droppable;
  37. this.AddManipulator(new SelectionDropper());
  38. Profiler.EndSample();
  39. style.position = PositionType.Relative;
  40. }
  41. // On purpose -- until we support Drag&Drop I suppose
  42. public override void SetPosition(Rect newPos)
  43. {
  44. style.position = PositionType.Relative;
  45. }
  46. void OnToggleEnable(ChangeEvent<bool> e)
  47. {
  48. controller.model.enabled = !controller.model.enabled;
  49. }
  50. protected override void SelfChange()
  51. {
  52. base.SelfChange();
  53. if (controller.model.enabled)
  54. RemoveFromClassList("block-disabled");
  55. else
  56. AddToClassList("block-disabled");
  57. m_EnableToggle.SetValueWithoutNotify(controller.model.enabled);
  58. if (!controller.model.isValid)
  59. AddToClassList("invalid");
  60. else
  61. RemoveFromClassList("invalid");
  62. }
  63. public override bool superCollapsed
  64. {
  65. get { return false; }
  66. }
  67. }
  68. }