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