TextureArraySlotControlView.cs 1.2 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 TextureArraySlotControlView : VisualElement
  10. {
  11. Texture2DArrayInputMaterialSlot m_Slot;
  12. public TextureArraySlotControlView(Texture2DArrayInputMaterialSlot slot)
  13. {
  14. m_Slot = slot;
  15. styleSheets.Add(Resources.Load<StyleSheet>("Styles/Controls/TextureArraySlotControlView"));
  16. var objectField = new ObjectField { objectType = typeof(Texture2DArray), value = m_Slot.textureArray };
  17. objectField.RegisterValueChangedCallback(OnValueChanged);
  18. Add(objectField);
  19. }
  20. void OnValueChanged(ChangeEvent<Object> evt)
  21. {
  22. var textureArray = evt.newValue as Texture2DArray;
  23. if (textureArray != m_Slot.textureArray)
  24. {
  25. m_Slot.owner.owner.owner.RegisterCompleteObjectUndo("Change Texture Array");
  26. m_Slot.textureArray = textureArray;
  27. m_Slot.owner.Dirty(ModificationScope.Node);
  28. }
  29. }
  30. }
  31. }