Ingen beskrivning
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.

Texture3DInputMaterialSlot.cs 3.5KB

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(MinimalTexture3DInputMaterialSlot))]
  12. class Texture3DInputMaterialSlot : Texture3DMaterialSlot
  13. {
  14. [SerializeField]
  15. private SerializableTexture m_Texture = new SerializableTexture();
  16. public Texture texture
  17. {
  18. get { return m_Texture.texture; }
  19. set { m_Texture.texture = value; }
  20. }
  21. public override bool isDefaultValue => texture == null;
  22. public Texture3DInputMaterialSlot()
  23. { }
  24. public Texture3DInputMaterialSlot(
  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 Texture3DSlotControlView(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 $"UnityBuildTexture3DStruct({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 Texture3DShaderProperty();
  49. prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id);
  50. prop.modifiable = false;
  51. prop.generatePropertyBlock = true;
  52. prop.value.texture = texture;
  53. properties.AddShaderProperty(prop);
  54. }
  55. public override void GetPreviewProperties(List<PreviewProperty> properties, string name)
  56. {
  57. var pp = new PreviewProperty(PropertyType.Texture3D)
  58. {
  59. name = name,
  60. textureValue = texture,
  61. };
  62. properties.Add(pp);
  63. }
  64. public override void CopyValuesFrom(MaterialSlot foundSlot)
  65. {
  66. var slot = foundSlot as Texture3DInputMaterialSlot;
  67. if (slot != null)
  68. {
  69. m_Texture = slot.m_Texture;
  70. bareResource = slot.bareResource;
  71. }
  72. }
  73. }
  74. class MinimalTexture3DInputMaterialSlot : IHasDependencies
  75. {
  76. [SerializeField]
  77. private SerializableTexture m_Texture = null;
  78. public void GetSourceAssetDependencies(AssetCollection assetCollection)
  79. {
  80. var guidString = m_Texture.guid;
  81. if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid))
  82. {
  83. assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage);
  84. }
  85. }
  86. }
  87. }