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