No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Texture2DArrayInputMaterialSlot.cs 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor.Graphing;
  4. using UnityEditor.ShaderGraph.Drawing.Slots;
  5. using UnityEditor.ShaderGraph.Internal;
  6. using UnityEngine;
  7. using UnityEngine.UIElements;
  8. namespace UnityEditor.ShaderGraph
  9. {
  10. [Serializable]
  11. [HasDependencies(typeof(MinimalTexture2DArrayInputMaterialSlot))]
  12. class Texture2DArrayInputMaterialSlot : Texture2DArrayMaterialSlot
  13. {
  14. [SerializeField]
  15. private SerializableTextureArray m_TextureArray = new SerializableTextureArray();
  16. public Texture2DArray textureArray
  17. {
  18. get { return m_TextureArray.textureArray; }
  19. set { m_TextureArray.textureArray = value; }
  20. }
  21. public override bool isDefaultValue => textureArray == null;
  22. public Texture2DArrayInputMaterialSlot()
  23. { }
  24. public Texture2DArrayInputMaterialSlot(
  25. int slotId,
  26. string displayName,
  27. string shaderOutputName,
  28. ShaderStageCapability shaderStageCapability = ShaderStageCapability.All,
  29. bool hidden = false)
  30. : base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStageCapability, hidden)
  31. { }
  32. public override VisualElement InstantiateControl()
  33. {
  34. return new TextureArraySlotControlView(this);
  35. }
  36. public override string GetDefaultValue(GenerationMode generationMode)
  37. {
  38. var nodeOwner = owner as AbstractMaterialNode;
  39. if (nodeOwner == null)
  40. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  41. return $"UnityBuildTexture2DArrayStruct({nodeOwner.GetVariableNameForSlot(id)})";
  42. }
  43. public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)
  44. {
  45. var nodeOwner = owner as AbstractMaterialNode;
  46. if (nodeOwner == null)
  47. throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode)));
  48. var prop = new Texture2DArrayShaderProperty();
  49. prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id);
  50. prop.modifiable = false;
  51. prop.generatePropertyBlock = true;
  52. prop.value.textureArray = textureArray;
  53. properties.AddShaderProperty(prop);
  54. }
  55. public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
  56. {
  57. var pp = new PreviewProperty(PropertyType.Texture2DArray)
  58. {
  59. name = name,
  60. textureValue = textureArray,
  61. };
  62. properties.Add(pp);
  63. }
  64. public override void CopyValuesFrom(MaterialSlot foundSlot)
  65. {
  66. var slot = foundSlot as Texture2DArrayInputMaterialSlot;
  67. if (slot != null)
  68. {
  69. m_TextureArray = slot.m_TextureArray;
  70. bareResource = slot.bareResource;
  71. }
  72. }
  73. }
  74. class MinimalTexture2DArrayInputMaterialSlot : IHasDependencies
  75. {
  76. [SerializeField]
  77. private SerializableTextureArray m_TextureArray = null;
  78. public void GetSourceAssetDependencies(AssetCollection assetCollection)
  79. {
  80. var guidString = m_TextureArray.guid;
  81. if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid))
  82. {
  83. assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage);
  84. }
  85. }
  86. }
  87. }