UVSlotControlView.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Internal;
  4. using UnityEditor.UIElements;
  5. using UnityEngine;
  6. using UnityEngine.UIElements;
  7. namespace UnityEditor.ShaderGraph.Drawing.Slots
  8. {
  9. class UVSlotControlView : VisualElement
  10. {
  11. UVMaterialSlot m_Slot;
  12. public UVSlotControlView(UVMaterialSlot slot)
  13. {
  14. styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/UVSlotControlView"));
  15. m_Slot = slot;
  16. var enumField = new EnumField(slot.channel);
  17. enumField.RegisterValueChangedCallback(OnValueChanged);
  18. Add(enumField);
  19. }
  20. void OnValueChanged(ChangeEvent<Enum> evt)
  21. {
  22. var channel = (UVChannel)evt.newValue;
  23. if (channel != m_Slot.channel)
  24. {
  25. m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change UV Channel");
  26. m_Slot.channel = channel;
  27. m_Slot.owner.Dirty(ModificationScope.Graph);
  28. }
  29. }
  30. }
  31. }