Texture3DSlotControlView.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEngine;
  4. using Object = UnityEngine.Object;
  5. using UnityEditor.UIElements;
  6. using UnityEngine.UIElements;
  7. namespace UnityEditor.ShaderGraph.Drawing.Slots
  8. {
  9. class Texture3DSlotControlView : VisualElement
  10. {
  11. Texture3DInputMaterialSlot m_Slot;
  12. public Texture3DSlotControlView(Texture3DInputMaterialSlot slot)
  13. {
  14. m_Slot = slot;
  15. styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/Texture3DSlotControlView"));
  16. var objectField = new ObjectField { objectType = typeof(Texture3D), value = m_Slot.texture };
  17. objectField.RegisterValueChangedCallback(OnValueChanged);
  18. Add(objectField);
  19. }
  20. void OnValueChanged(ChangeEvent<Object> evt)
  21. {
  22. var texture = evt.newValue as Texture3D;
  23. if (texture != m_Slot.texture)
  24. {
  25. m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Texture");
  26. m_Slot.texture = texture;
  27. m_Slot.owner.Dirty(ModificationScope.Node);
  28. }
  29. }
  30. }
  31. }