UVMaterialSlot.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Drawing.Slots;
  4. using UnityEditor.ShaderGraph.Internal;
  5. using UnityEngine;
  6. using UnityEngine.UIElements;
  7. namespace UnityEditor.ShaderGraph
  8. {
  9. [Serializable]
  10. class UVMaterialSlot : Vector2MaterialSlot, IMayRequireMeshUV
  11. {
  12. [SerializeField]
  13. UVChannel m_Channel = UVChannel.UV0;
  14. public UVChannel channel
  15. {
  16. get { return m_Channel; }
  17. set { m_Channel = value; }
  18. }
  19. public UVMaterialSlot()
  20. {}
  21. public UVMaterialSlot(int slotId, string displayName, string shaderOutputName, UVChannel channel,
  22. ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
  23. : base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, stageCapability, hidden: hidden)
  24. {
  25. this.channel = channel;
  26. }
  27. public override VisualElement InstantiateControl()
  28. {
  29. return new UVSlotControlView(this);
  30. }
  31. public override string GetDefaultValue(GenerationMode generationMode)
  32. {
  33. return string.Format("IN.{0}.xy", channel.GetUVName());
  34. }
  35. public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
  36. {
  37. if (isConnected)
  38. return false;
  39. return m_Channel == channel;
  40. }
  41. public override void CopyValuesFrom(MaterialSlot foundSlot)
  42. {
  43. var slot = foundSlot as UVMaterialSlot;
  44. if (slot != null)
  45. channel = slot.channel;
  46. }
  47. }
  48. }