A game about forced loneliness, made by TACStudios
at master 3.5 kB view raw
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(MinimalTexture3DInputMaterialSlot))] 13 class Texture3DInputMaterialSlot : Texture3DMaterialSlot 14 { 15 [SerializeField] 16 private SerializableTexture m_Texture = new SerializableTexture(); 17 18 public Texture texture 19 { 20 get { return m_Texture.texture; } 21 set { m_Texture.texture = value; } 22 } 23 24 public override bool isDefaultValue => texture == null; 25 26 public Texture3DInputMaterialSlot() 27 { } 28 29 public Texture3DInputMaterialSlot( 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 Texture3DSlotControlView(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 $"UnityBuildTexture3DStruct({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 Texture3DShaderProperty(); 59 prop.overrideReferenceName = nodeOwner.GetVariableNameForSlot(id); 60 prop.modifiable = false; 61 prop.generatePropertyBlock = true; 62 prop.value.texture = texture; 63 properties.AddShaderProperty(prop); 64 } 65 66 public override void GetPreviewProperties(List<PreviewProperty> properties, string name) 67 { 68 var pp = new PreviewProperty(PropertyType.Texture3D) 69 { 70 name = name, 71 textureValue = texture, 72 }; 73 properties.Add(pp); 74 } 75 76 public override void CopyValuesFrom(MaterialSlot foundSlot) 77 { 78 var slot = foundSlot as Texture3DInputMaterialSlot; 79 if (slot != null) 80 { 81 m_Texture = slot.m_Texture; 82 bareResource = slot.bareResource; 83 } 84 } 85 } 86 87 class MinimalTexture3DInputMaterialSlot : IHasDependencies 88 { 89 [SerializeField] 90 private SerializableTexture 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}