ScreenPositionMaterialSlot.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using UnityEditor.Graphing;
  3. using UnityEditor.ShaderGraph.Drawing.Slots;
  4. using UnityEngine;
  5. using UnityEngine.UIElements;
  6. namespace UnityEditor.ShaderGraph
  7. {
  8. [Serializable]
  9. class ScreenPositionMaterialSlot : Vector4MaterialSlot, IMayRequireScreenPosition
  10. {
  11. [SerializeField]
  12. ScreenSpaceType m_ScreenSpaceType;
  13. public ScreenSpaceType screenSpaceType
  14. {
  15. get { return m_ScreenSpaceType; }
  16. set { m_ScreenSpaceType = value; }
  17. }
  18. public ScreenPositionMaterialSlot()
  19. {}
  20. public ScreenPositionMaterialSlot(int slotId, string displayName, string shaderOutputName, ScreenSpaceType screenSpaceType,
  21. ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
  22. : base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, stageCapability, hidden: hidden)
  23. {
  24. this.screenSpaceType = screenSpaceType;
  25. }
  26. public override VisualElement InstantiateControl()
  27. {
  28. return new ScreenPositionSlotControlView(this);
  29. }
  30. public override string GetDefaultValue(GenerationMode generationMode)
  31. {
  32. return m_ScreenSpaceType.ToValueAsVariable();
  33. }
  34. public bool RequiresScreenPosition(ShaderStageCapability stageCapability)
  35. {
  36. return !isConnected;
  37. }
  38. public override void CopyValuesFrom(MaterialSlot foundSlot)
  39. {
  40. var slot = foundSlot as ScreenPositionMaterialSlot;
  41. if (slot != null)
  42. screenSpaceType = slot.screenSpaceType;
  43. }
  44. }
  45. }