A game about forced loneliness, made by TACStudios
at master 3.2 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 class Matrix2MaterialSlot : MaterialSlot, IMaterialSlotHasValue<Matrix4x4> 14 { 15 [SerializeField] 16 private Matrix4x4 m_Value = Matrix4x4.identity; 17 18 [SerializeField] 19 private Matrix4x4 m_DefaultValue = Matrix4x4.identity; 20 21 public Matrix2MaterialSlot() 22 { 23 } 24 25 public Matrix2MaterialSlot( 26 int slotId, 27 string displayName, 28 string shaderOutputName, 29 SlotType slotType, 30 ShaderStageCapability stageCapability = ShaderStageCapability.All, 31 bool hidden = false) 32 : base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden) 33 { 34 } 35 36 public override VisualElement InstantiateControl() 37 { 38 return new LabelSlotControlView("Identity"); 39 } 40 41 public Matrix4x4 defaultValue { get { return m_DefaultValue; } } 42 43 public Matrix4x4 value 44 { 45 get { return m_Value; } 46 set { m_Value = value; } 47 } 48 49 public override bool isDefaultValue => value.Equals(defaultValue); 50 51 protected override string ConcreteSlotValueAsVariable() 52 { 53 return "$precision2x2 (1,0,0,1)"; 54 } 55 56 public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode) 57 { 58 if (!generationMode.IsPreview()) 59 return; 60 61 var matOwner = owner as AbstractMaterialNode; 62 if (matOwner == null) 63 throw new Exception(string.Format("Slot {0} either has no owner, or the owner is not a {1}", this, typeof(AbstractMaterialNode))); 64 65 var property = new Matrix2ShaderProperty() 66 { 67 overrideReferenceName = matOwner.GetVariableNameForSlot(id), 68 generatePropertyBlock = false, 69 value = value 70 }; 71 properties.AddShaderProperty(property); 72 } 73 74 public override void GetPreviewProperties(List<PreviewProperty> properties, string name) 75 { 76 var pp = new PreviewProperty(PropertyType.Matrix2) 77 { 78 name = name, 79 matrixValue = value 80 }; 81 properties.Add(pp); 82 } 83 84 public override SlotValueType valueType { get { return SlotValueType.Matrix2; } } 85 public override ConcreteSlotValueType concreteValueType { get { return ConcreteSlotValueType.Matrix2; } } 86 87 public override void CopyValuesFrom(MaterialSlot foundSlot) 88 { 89 var slot = foundSlot as Matrix2MaterialSlot; 90 if (slot != null) 91 value = slot.value; 92 } 93 94 public override void CopyDefaultValue(MaterialSlot other) 95 { 96 base.CopyDefaultValue(other); 97 if (other is IMaterialSlotHasValue<Matrix4x4> ms) 98 { 99 m_DefaultValue = ms.defaultValue; 100 } 101 } 102 } 103}