Texture3DAssetNode.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using UnityEditor.ShaderGraph.Drawing.Controls;
  3. using UnityEngine;
  4. using UnityEditor.Graphing;
  5. using UnityEditor.ShaderGraph.Internal;
  6. namespace UnityEditor.ShaderGraph
  7. {
  8. [Title("Input", "Texture", "Texture 3D Asset")]
  9. class Texture3DAssetNode : AbstractMaterialNode, IPropertyFromNode
  10. {
  11. public const int OutputSlotId = 0;
  12. const string kOutputSlotName = "Out";
  13. public Texture3DAssetNode()
  14. {
  15. name = "Texture 3D Asset";
  16. UpdateNodeAfterDeserialization();
  17. }
  18. public sealed override void UpdateNodeAfterDeserialization()
  19. {
  20. AddSlot(new Texture3DMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
  21. RemoveSlotsNameNotMatching(new[] { OutputSlotId });
  22. }
  23. [SerializeField]
  24. private SerializableTexture m_Texture = new SerializableTexture();
  25. [Texture3DControl("")]
  26. public Texture3D texture
  27. {
  28. get { return m_Texture.texture as Texture3D; }
  29. set
  30. {
  31. if (m_Texture.texture == value)
  32. return;
  33. m_Texture.texture = value;
  34. Dirty(ModificationScope.Node);
  35. }
  36. }
  37. public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
  38. {
  39. properties.AddShaderProperty(new Texture3DShaderProperty()
  40. {
  41. overrideReferenceName = GetVariableNameForSlot(OutputSlotId),
  42. generatePropertyBlock = true,
  43. value = m_Texture,
  44. modifiable = false
  45. });
  46. }
  47. public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
  48. {
  49. properties.Add(new PreviewProperty(PropertyType.Texture3D)
  50. {
  51. name = GetVariableNameForSlot(OutputSlotId),
  52. textureValue = texture
  53. });
  54. }
  55. public AbstractShaderProperty AsShaderProperty()
  56. {
  57. var prop = new Texture3DShaderProperty { value = m_Texture };
  58. if (texture != null)
  59. prop.displayName = texture.name;
  60. return prop;
  61. }
  62. public int outputSlotId { get { return OutputSlotId; } }
  63. }
  64. }