A game about forced loneliness, made by TACStudios
at master 101 lines 3.3 kB view raw
1using System.Collections.Generic; 2using UnityEditor.ShaderGraph.Drawing.Controls; 3using UnityEngine; 4using UnityEditor.Graphing; 5using UnityEditor.ShaderGraph.Internal; 6 7namespace UnityEditor.ShaderGraph 8{ 9 [Title("Input", "Texture", "Texture 2D Array Asset")] 10 [HasDependencies(typeof(Minimal2dArrayTextureAssetNode))] 11 class Texture2DArrayAssetNode : AbstractMaterialNode, IPropertyFromNode 12 { 13 public const int OutputSlotId = 0; 14 15 const string kOutputSlotName = "Out"; 16 17 public Texture2DArrayAssetNode() 18 { 19 name = "Texture 2D Array Asset"; 20 synonyms = new string[] { "stack", "pile" }; 21 UpdateNodeAfterDeserialization(); 22 } 23 24 public sealed override void UpdateNodeAfterDeserialization() 25 { 26 AddSlot(new Texture2DArrayMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output)); 27 RemoveSlotsNameNotMatching(new[] { OutputSlotId }); 28 } 29 30 [SerializeField] 31 private SerializableTextureArray m_Texture = new SerializableTextureArray(); 32 33 [TextureArrayControl("")] 34 public Texture2DArray texture 35 { 36 get { return m_Texture.textureArray; } 37 set 38 { 39 if (m_Texture.textureArray == value) 40 return; 41 m_Texture.textureArray = value; 42 Dirty(ModificationScope.Node); 43 } 44 } 45 46 string GetTexturePropertyName() 47 { 48 return base.GetVariableNameForSlot(OutputSlotId); 49 } 50 51 public override string GetVariableNameForSlot(int slotId) 52 { 53 return $"UnityBuildTexture2DArrayStruct({GetTexturePropertyName()})"; 54 } 55 56 public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode) 57 { 58 properties.AddShaderProperty(new Texture2DArrayShaderProperty() 59 { 60 overrideReferenceName = GetTexturePropertyName(), 61 generatePropertyBlock = true, 62 value = m_Texture, 63 modifiable = false 64 }); 65 } 66 67 public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties) 68 { 69 properties.Add(new PreviewProperty(PropertyType.Texture2DArray) 70 { 71 name = GetTexturePropertyName(), 72 textureValue = texture 73 }); 74 } 75 76 public AbstractShaderProperty AsShaderProperty() 77 { 78 var prop = new Texture2DArrayShaderProperty { value = m_Texture }; 79 if (texture != null) 80 prop.displayName = texture.name; 81 return prop; 82 } 83 84 public int outputSlotId { get { return OutputSlotId; } } 85 } 86 87 class Minimal2dArrayTextureAssetNode : IHasDependencies 88 { 89 [SerializeField] 90 private SerializableTextureArray m_Texture = null; 91 92 public void GetSourceAssetDependencies(AssetCollection assetCollection) 93 { 94 var guidString = m_Texture.guid; 95 if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid)) 96 { 97 assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage); 98 } 99 } 100 } 101}